private static void ExecuteResponseReceived(object arg) { ExecuteCallbackArgs <ClientHttpRequestCompletedEventArgs> callbackArgs = (ExecuteCallbackArgs <ClientHttpRequestCompletedEventArgs>)arg; if (callbackArgs.Callback != null) { callbackArgs.Callback(callbackArgs.EventArgs); } }
// This is the method that the underlying, free-threaded asynchronous behavior will invoke. // This will happen on an arbitrary thread. private void ExecuteAsyncCallback(ExecuteState state, IClientHttpResponse response, Exception exception) { // Package the results of the operation ClientHttpRequestCompletedEventArgs eventArgs = new ClientHttpRequestCompletedEventArgs(response, exception, this.isCancelled, state.AsyncOperation.UserSuppliedState); ExecuteCallbackArgs <ClientHttpRequestCompletedEventArgs> callbackArgs = new ExecuteCallbackArgs <ClientHttpRequestCompletedEventArgs>(eventArgs, state.ExecuteCompleted); // End the task. The asyncOp object is responsible for marshaling the call. state.AsyncOperation.PostOperationCompleted(ExecuteResponseReceived, callbackArgs); }