Created
March 4, 2018 12:19
-
-
Save mishrsud/3cdad9dcb98a9dbfc738ddae59cc44cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var jobExecutor = new JobExecutor(); | |
Task t = Task.Run(() => jobExecutor.DoJob()); | |
t.ConfigureAwait(false); | |
Task t2 = Task.Run(() => jobExecutor.DoJob()); | |
t2.ConfigureAwait(false); | |
Task t3 = Task.Run(() => jobExecutor.DoJob()); | |
t3.ConfigureAwait(false); | |
var allTasks = new List<Task> | |
{ | |
t,t2,t3 | |
}; | |
allTasks.ForEach(task => task.ContinueWith(t1 => | |
{ | |
var x = t1.Exception; | |
Console.WriteLine("Exception in Task"); | |
Console.WriteLine(x.InnerException); | |
}, | |
CancellationToken.None, | |
TaskContinuationOptions.OnlyOnFaulted, | |
TaskScheduler.Default)); | |
// TaskScheduler.UnobservedTaskException += (w, s) => | |
// { | |
// Console.WriteLine($"From Unobserved exception: {s.Exception}"); | |
// Console.WriteLine($"Is Observed: {s.Observed}"); | |
// s.SetObserved(); | |
// }; | |
} | |
// Define other methods and classes here | |
public class JobExecutor | |
{ | |
public void DoJob() | |
{ | |
Task.Delay(TimeSpan.FromSeconds(2)).Wait(); | |
throw new ApplicationException("Boom"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment