コード例 #1
0
            private static Task CreateGenericTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                TaskCompletionSourceProxy      tcsp = new TaskCompletionSourceProxy(operation.TaskTResult);
                Action <Task <object>, object> completeCallDelegate = (antecedent, obj) =>
                {
                    var tcsProxy = obj as TaskCompletionSourceProxy;
                    Contract.Assert(tcsProxy != null);
                    if (antecedent.IsFaulted)
                    {
                        tcsProxy.TrySetException(antecedent.Exception.InnerException);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        tcsProxy.TrySetCanceled();
                    }
                    else
                    {
                        tcsProxy.TrySetResult(antecedent.Result);
                    }
                };

                try
                {
                    channel.CallAsync(operation.Action, operation.IsOneWay, operation, inputParameters,
                                      Array.Empty <object>()).ContinueWith(completeCallDelegate, tcsp);
                }
#pragma warning disable CA1031 // Do not catch general exception types - copying all exceptions to TaskCompeletionSource
                catch (Exception e)
                {
                    tcsp.TrySetException(e);
                }
#pragma warning restore CA1031 // Do not catch general exception types

                return(tcsp.Task);
            }
コード例 #2
0
            private static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

                Action <Task <object>, object> completeCallDelegate = (antecedent, obj) =>
                {
                    var tcsObj = obj as TaskCompletionSource <object>;
                    Contract.Assert(tcsObj != null);
                    if (antecedent.IsFaulted)
                    {
                        tcsObj.TrySetException(antecedent.Exception.InnerException);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        tcsObj.TrySetCanceled();
                    }
                    else
                    {
                        tcsObj.TrySetResult(antecedent.Result);
                    }
                };


                try
                {
                    channel.CallAsync(operation.Action, operation.IsOneWay, operation, inputParameters,
                                      Array.Empty <object>()).ContinueWith(completeCallDelegate, tcs);
                }
                catch (Exception e)
                {
                    tcs.TrySetException(e);
                }

                return(tcs.Task);
            }
コード例 #3
0
        private object InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            object[] ins = operation.MapSyncInputs(methodCall, out object[] outs);
            object   ret;

            using (TaskHelpers.RunTaskContinuationsOnOurThreads())
            {
                ret = _serviceChannel.CallAsync(operation.Action, operation.IsOneWay, operation, ins, outs).GetAwaiter().GetResult();
            }
            operation.MapSyncOutputs(methodCall, outs, ref ret);
            return(ret);
        }