Tag: 异步服务

Azure ServiceBus和async – 是或不是?

我正在Azure上运行Service Bus, 每秒抽取大约10-100条消息 。 最近我转而使用.net 4.5并且所有兴奋重构的所有代码都在每行中至少有两次‘async’和’await ‘,以确保它’正确’完成’:) 现在我想知道它实际上是好还是坏 。 如果你能看一下代码片段,请告诉我你的想法。 我特别担心,如果线程上下文切换没有给我带来更多的悲伤而不是从所有异步中获益……(看看!dumpheap肯定是一个因素) 只是一点描述 – 我将发布2个方法 – 一个在ConcurrentQueue上执行while循环,等待新消息和另一个一次发送一条消息的方法。 我也正如Azure博士所规定的那样使用Transient Fault Handling块。 发送循环(从头开始,等待新消息): private async void SendingLoop() { try { await this.RecreateMessageFactory(); this.loopSemaphore.Reset(); Buffer message = null; while (true) { if (this.cancel.Token.IsCancellationRequested) { break; } this.semaphore.WaitOne(); if (this.cancel.Token.IsCancellationRequested) { break; } while (this.queue.TryDequeue(out message)) { try { using […]