unobserved-exception

How to clean up after a failed AsyncDuplexStreamingCall?

夙愿已清 提交于 2020-03-05 04:54:29
问题 I have a AsyncDuplexStreamingCall that fails on the server side at the first write to the request stream. This will result in an RpcException at that point on the client side, as I'd expect. Today, however, I noticed an UnobservedTaskException and figured out that I also have to ensure that the response stream is not left in an error state: var call = _client.HelloWorld(); try { await call.RequestStream.WriteAsync(...); // fails with an RpcException, as expected ... } catch (RpcException) { /

How to handle all unhandled exceptions when using Task Parallel Library?

拈花ヽ惹草 提交于 2019-12-17 06:28:22
问题 I'm using the TPL (Task Parallel Library) in .NET 4.0. I want to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads started with TPL code, e.g. Task.Factory.StartNew(...) . The event is indeed fired if I use something like new Thread(threadStart).Start() . This MSDN article suggests to use Task.Wait() to catch the AggregateException when working with TPL, but that

How to handle all unhandled exceptions when using Task Parallel Library?

霸气de小男生 提交于 2019-12-17 06:28:19
问题 I'm using the TPL (Task Parallel Library) in .NET 4.0. I want to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads started with TPL code, e.g. Task.Factory.StartNew(...) . The event is indeed fired if I use something like new Thread(threadStart).Start() . This MSDN article suggests to use Task.Wait() to catch the AggregateException when working with TPL, but that

UnobservedTaskException is not killing the process

[亡魂溺海] 提交于 2019-12-10 17:28:58
问题 I am trying to understand the UnobservedTaskException issue in .NET 4.0 so I wrote the folloging code TaskScheduler.UnobservedTaskException += (sender, eventArgs) => Console.WriteLine("unobserved"); Task.Factory.StartNew(() => { throw new Exception(); }, TaskCreationOptions.LongRunning); using (var autoResetEvent = new AutoResetEvent(false)) { autoResetEvent.WaitOne(TimeSpan.FromSeconds(10)); } Console.WriteLine("Collecting"); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(

The operation was canceled at TaskScheduler.UnobservedTaskException in WebAPI

那年仲夏 提交于 2019-12-10 13:47:05
问题 Recently I have added error logging for every UnobservedTaskException at my backend API app. The reason is that some API call executes additional tasks which are finished AFTER I return the result, that is why I couldn't track errors there on action (web api calls) level. Now I'm getting lots of "The operation was canceled" exceptions and not sure what to do with it. I even not sure that this exception is caused by my tasks executed by API call. Here is stack: System

Test for UnObserved Exceptions

半腔热情 提交于 2019-12-07 02:28:42
问题 I have a C# Extension method that can be used with tasks to make sure any exceptions thrown are at the very minimum observed, so as to not crash the hosting process. In .NET4.5, the behavior has changed slightly so this won't happen, however the unobserved exception event is still triggered. My challenge here is writing a test to prove the extension method works. I am using NUnit Test Framework and ReSharper is the test runner. I have tried: var wasUnobservedException = false; TaskScheduler