Skip to content

Instantly share code, notes, and snippets.

@pictos
Created March 27, 2023 14:16
Show Gist options
  • Save pictos/aa0285e428dbe57eaaffe2d629956a5d to your computer and use it in GitHub Desktop.
Save pictos/aa0285e428dbe57eaaffe2d629956a5d to your computer and use it in GitHub Desktop.
/*
SharpLab tools in Run mode:
• value.Inspect()
• Inspect.Heap(object)
• Inspect.Stack(value)
• Inspect.MemoryGraph(value1, value2, …)
*/
using System;
using System.Threading.Tasks;
Console.WriteLine("🌄");
//DoSomething_Awating().FireAndForget(e => Console.WriteLine(e.Message));
DoSomething_ReturningTask().FireAndForget(e => Console.WriteLine(e.Message));
await Task.Delay(3000);
static Task DoSomething_ReturningTask()
{
throw new Exception("My one");
return Task.Delay(2000);
}
static async Task DoSomething_Awating()
{
throw new Exception("My one");
await Task.Delay(500);
}
static class TaskEx
{
public static void FireAndForget(this Task task, Action<Exception>? errorHandler = null)
{
task.ContinueWith(t =>
{
Console.WriteLine(t.Exception.GetType());
if (t.IsFaulted && errorHandler != null)
errorHandler(t.Exception.InnerException);
}, TaskContinuationOptions.OnlyOnFaulted);
}
}
@pictos
Copy link
Author

pictos commented Mar 27, 2023

you can run that code from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment