private void Run() { innerTask = Task.Run(async() => { while (ShouldContinueWork()) { try { if (asyncAction != null) { await asyncAction(); } action?.Invoke(); await Task.Delay(timeSpan, token); } catch (OperationCanceledException) { return; } catch (Exception e) { exceptionAction?.Invoke(e); if (exceptionAction == null) { FridayDebugger.Log(e); } } } }, token); }
/// <summary> /// Prevents UnobservedTaskException /// </summary> public static void AttachDefaultExceptionHandler(this Task task) { task.ContinueWith(task1 => FridayDebugger.LogFailedTask(task), TaskContinuationOptions.OnlyOnFaulted).ConfigureAwait(false); }