求救,ASP.NET消息队列,如何判断队列里面已经没有消息了

周睿 2011-03-24 03:55:14
公司需要传输一些文件,刚解决了分块传输的问题,但无法判断队列里面已经没有消息了???

如果判断?还有,消息发送后,没有回传值,我怎么知道它到底队列没???

请给出稍微详细的代码,马上就结贴的
...全文
232 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
周睿 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 doulestring 的回复:]

C# code

/// <summary>
/// 连接消息队列并从队列中接收消息
/// </summary>
public static int ReceiveMessage(string fileName)
{

byte[] data;
int le……
[/Quote]??
子夜__ 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 doulestring 的回复:]

C# code

/// <summary>
/// 连接消息队列并从队列中接收消息
/// </summary>
public static int ReceiveMessage(string fileName)
{

byte[] data;
int le……
[/Quote]
MSDN?
周睿 2011-03-24
  • 打赏
  • 举报
回复

/// <summary>
/// 连接消息队列并从队列中接收消息
/// </summary>
public static int ReceiveMessage(string fileName)
{

byte[] data;
int length,i=0;
//打开已经存在的链接
MessageQueue queue = new MessageQueue(".\\private$\\queuenew");
queue.MessageReadPropertyFilter.CorrelationId = true;
queue.MessageReadPropertyFilter.AppSpecific = true;
try
{
//开启文件流
using (FileStream fs = File.OpenWrite(fileName))
{

MessageQueueTransaction Transaction = new MessageQueueTransaction();
//启动事务
Transaction.Begin();
//接收第一个消息
System.Messaging.Message msg = queue.Receive(new TimeSpan(0, 0, 1), Transaction);
string id = msg.Id;
//Get the Lenght of the message body stream
length = Convert.ToInt32(msg.BodyStream.Length);
//Create a buffer to hold the stream in memory
data = new byte[length];
//Read the body stream
msg.BodyStream.Read(data, 0, length);
//Write the buffer into the file
fs.Write(data, 0, length);
//Receive following message
i = 1;
msg = queue.Peek(new TimeSpan(0, 0, 1));
while (msg.CorrelationId == id)
{
//Get the Lenght of the message body stream
length = Convert.ToInt32(msg.BodyStream.Length);
//Create a buffer to hold the stream in memory
data = new byte[length];
//Read the body stream
msg.BodyStream.Read(data, 0, length);
//Write the buffer into the file
fs.Write(data, 0, length);
//Receive following message
msg = queue.Receive(new TimeSpan(0, 0, 1), Transaction);
id = msg.Id;
//如何判断队列已经空了??
msg = queue.Peek(new TimeSpan(0, 0, 1));
i = 1;
}
Transaction.Commit();
}
}
catch (Exception ex)
{
i = 0;
MessageBox.Show(ex.Message);
}
finally
{
queue.Refresh();
//release queue resources
queue.Close();
}
return i;
}
chen_ya_ping 2011-03-24
  • 打赏
  • 举报
回复
我看楼主还是要先给出你自己的代码,然后让大家明白你讲的队列,上面都给出了2个队列,一个是基本的数据结构,一个是windows消息队列,那楼主你说的是哪个队列呢?
周睿 2011-03-24
  • 打赏
  • 举报
回复
windows消息队列
zhongweng 2011-03-24
  • 打赏
  • 举报
回复
http://baike.baidu.com/view/38959.htm 看下吧 或许会有帮助

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧