实际上,根据我的经验,Service Bus 的速度非常快。你有什么问题是“Thread.Sleep(10000)”;
每条消息休眠 10 秒。对于 100 条消息 100*10 = 10000 秒 = 16.67 分钟所以这是延迟的问题......
解决方案:
不要使用 Thread.Sleep(10000); (不适合BeginReceive,只适合Receive)
public override void Run() //This should not be a Thread...If its a thread then your thread will terminate after receiving your first message
{
IAsyncResult result = CUDClient.BeginReceive(**TimeSpan.MaxValue**, OnMessageReceive, CUDClient);
}
//Function OnMessageReceive
{
//Process the Message
**IAsyncResult result = CUDClient.BeginReceive(TimeSpan.MaxValue, OnMessageReceive, CUDClient);**
}
使用 TimeSpan.MaxValue 您与 SB 的连接将被保留很长时间。所以没有频繁的空消息(更少的成本)......