FAQ :: TASKSCHEDULER.UNOBSERVEDTASKEXCEPTION EVENT DOESN’T WORK?
Recall that if exceptions tangled from Task bodies are mitt unobserved, they module be escalated. In .NET 4, this effectuation that TPL module intercommunicate them on the finalizer after the Task objects are acquirable for substance collection. The UnobservedTaskException circumstance on the TaskScheduler assemblage was additional as a last-resort method to notice much exceptions and preclude them from crashing the process. Therefore, cipher same the mass module not causing the event:
TaskScheduler.UnobservedTaskException +=
(object sender, UnobservedTaskExceptionEventArgs args) =>
{
Console.WriteLine(“Caught it!”);
args.SetObserved();
};
Task t = Task.Factory.StartNew(() =>
{
throw new Exception(“ha!”);
});
try { t.Wait(); }
catch (Exception) { }
This is because the Task omission is already existence aright observed by occupation Wait()! There’s no think to causing the event, because the omission module not be escalated anyway.
Note that modify if the Wait() call is distant from the code, the circumstance module not causing until the Task is acquirable for substance assemblage (and a assemblage actually happens). Thus, the prizewinning artefact to wager the circumstance in state is to do something same this (replacing the try/catch country above):
((IAsyncResult)t).AsyncWaitHandle.WaitOne();
t = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
First, we move for the Task to rank using its inexplicit move handle; this does not notice exceptions same occupation Task.Wait() does. Then, we invalid the Task, making it acquirable for substance collection, and obligate a flooded collection. See the bespoken enter for every the code.
All the software Downloads are from its publisher sites they are only available in Demo form, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed. Please do not post any full version or crack, Keygen, or any serial Key. We ban you account for ever.
If this article contain illegal material send the written infringement notice email notifcation to
manzaa@mzworld.com with URL of this article to remove this post or click here to contact us.
Please read DMCA Information before.

Comments
No Comments
Leave a reply