private static void InternalUnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs e) { var aggrException = e.Exception; var baseException = aggrException.GetBaseException(); var tplTask = (Task)sender; var contextObj = tplTask.AsyncState; var context = contextObj as ISchedulingContext; try { if (unobservedExceptionHandler != null) { unobservedExceptionHandler(context, baseException); } } finally { if (e.Observed) { logger.Info(ErrorCode.Runtime_Error_100311, "UnobservedExceptionsHandlerClass caught an UnobservedTaskException which was successfully observed and recovered from. BaseException = {0}. Exception = {1}", baseException.Message, TraceLogger.PrintException(aggrException)); } else { var errorStr = String.Format("UnobservedExceptionsHandlerClass Caught an UnobservedTaskException event sent by {0}. Exception = {1}", OrleansTaskExtentions.ToString((Task)sender), TraceLogger.PrintException(aggrException)); logger.Error(ErrorCode.Runtime_Error_100005, errorStr); logger.Error(ErrorCode.Runtime_Error_100006, "Exception remained UnObserved!!! The subsequent behaivour depends on the ThrowUnobservedTaskExceptions setting in app config and .NET version."); } } }
internal Task Cancel() { // propagate the exception from the _cancellationTokenSource.Cancel back to the caller // but also cancel _targetGrainReferences. Task task = OrleansTaskExtentions.WrapInTask(_cancellationTokenSource.Cancel); if (_targetGrainReferences.IsEmpty) { return(task); } var cancellationTasks = _targetGrainReferences .Select(pair => pair.Value.AsReference <ICancellationSourcesExtension>() .CancelRemoteToken(this)) .ToList(); cancellationTasks.Add(task); return(Task.WhenAll(cancellationTasks)); }