我正在调用异步方法(具体来说:Microsoft.ServiceBus.Messaging.QueueClient.SendAsync())并且希望能够处理异常。
我遇到的一种可能性是:
_queueClient.SendAsync(message).ContinueWith((t) =>
{
Debug.WriteLine("Exception: " + t.Exception.InnerException.GetType().Name);
}, TaskContinuationOptions.OnlyOnFaulted);
然而,ContinueWith似乎被无限调用:
Exception: UnauthorizedAccessException
Exception: UnauthorizedAccessException
Exception: UnauthorizedAccessException
Exception: UnauthorizedAccessException
Exception: UnauthorizedAccessException
Exception: UnauthorizedAccessException
......................................
......etc
任何想法为什么会发生这种情况以及如何解决这个问题?
由于
答案 0 :(得分:0)
我在TraceListener中调用send,然后调用Debug.WriteLine并导致循环。
这意味着TraceListener会侦听跟踪,但它似乎也会侦听Debug消息。