This is an odd scenario, but I have a Task
in an unknown state. What I'd like to do is to be able to if it becomes Faulted
then cause an Application.UnhandledException
. Rather than TaskScheduler.UnobservedTaskException
which is what happens if I leave it alone.
await task
does work however this code needs to run in .NET 4 without any extra dependencies. So in essence I need to recreate the effect of await
ing the task.
task.ContinueWith(t => {
throw new InvalidOperationException();
},
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
SynchronizationContext.Current != null ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Current
);
The above code doesn't seem to do anything at the moment.
Any thoughts?