private static AsyncTaskCallInAdapter EndHelper(NativeCommon.IFabricAsyncOperationContext nativeContext) { AsyncTaskCallInAdapter adapter = nativeContext as AsyncTaskCallInAdapter; Requires.Argument <AsyncTaskCallInAdapter>("adapter", adapter).NotNull(); if (Interlocked.CompareExchange(ref adapter.wasEndCalled, 1, 0) != 0) { // calling end twice AppTrace.TraceSource.WriteError(adapter.functionTag, "AsyncTaskCallInAdapter.End was called twice"); ReleaseAssert.Failfast(string.Format(CultureInfo.CurrentCulture, StringResources.Error_AsyncTaskCallInAdapter_End_Called_Twice_Formatted, adapter.functionTag)); throw new InvalidOperationException(StringResources.Error_AsyncTaskCallInAdapter_End_Called_Twice); // ReleaseAssert.Fail will throw } AppTrace.TraceSource.WriteNoise(adapter.functionTag, "End"); try { adapter.userTask.Wait(); } catch (AggregateException ex) { Exception inner = ex.InnerException; AppTrace.TraceSource.WriteExceptionAsWarning(adapter.functionTag, inner, "Exception thrown during async task execution"); adapter.interopApi.HandleException(ex.GetBaseException()); Utility.TryTranslateManagedExceptionToCOMAndThrow(inner); throw inner; } return(adapter); }
public static TResult End <TResult>(NativeCommon.IFabricAsyncOperationContext nativeContext) { AsyncTaskCallInAdapter adapter = AsyncTaskCallInAdapter.EndHelper(nativeContext); return((adapter.userTask as Task <TResult>).Result); }
public static void End(NativeCommon.IFabricAsyncOperationContext nativeContext) { AsyncTaskCallInAdapter.EndHelper(nativeContext); }