bitwarden-android/src/Core/Utilities/TaskExtensions.cs

28 lines
888 B
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
namespace Bit.Core.Utilities
{
public static class TaskExtensions
{
/// <summary>
/// Fires a task and ignores any exception.
/// See http://stackoverflow.com/a/22864616/344182
/// </summary>
/// <param name="task">The task to be forgotten.</param>
/// <param name="onException">Action to be called on exception.</param>
public static async void FireAndForget(this Task task, Action<Exception> onException = null)
{
try
{
await task.ConfigureAwait(false);
}
catch (Exception ex)
{
onException?.Invoke(ex);
// TODO: Add app center exception handling in here, but we have to check whether we can add the AppCenter package to Core
}
}
}
}