mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
47 lines
932 B
C#
47 lines
932 B
C#
namespace Remotely.Shared.Extensions;
|
|
|
|
public static class TaskExtensions
|
|
{
|
|
public static async void Forget(this Task task, Func<Exception, Task>? exceptionHandler = null)
|
|
{
|
|
try
|
|
{
|
|
await task;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (exceptionHandler is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await exceptionHandler(ex);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
public static async void Forget<T>(this Task<T> task, Func<Exception, Task>? exceptionHandler = null)
|
|
{
|
|
try
|
|
{
|
|
await task;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (exceptionHandler is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await exceptionHandler(ex);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|