After reading the information about task management and exepcion, I use this code to control the exception created in the Task:
Task<Object> myTask = Task.Factory.StartNew<Object>(doTask, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); myTask .ContinueWith(task => afterTask(task), TaskScheduler.FromCurrentSynchronizationContext());
Where doTask and AfterTask:
private <Object> doTask() { throw new Exception("BOOM"); } private afterTask(Task<Object> aTask) { if (aTask.IsFaulted) { MessageBox.Show(aTask.Exception.InnerException.Message); } else
When an Exception Boom is raised, Visual Studio displays a warning warning that no exception has been detected, but if I continue to throw an exception, the afterTask function is processed.
Is this code correct, or am I missing some basic task behavior? Is there a way to avoid a warning from the debugger that it could not be caught? This is a little annoying ...
Thanks in advance
multithreading c # exception task
Ivan BASART
source share