当前位置: 首页>>代码示例>>C#>>正文


C# TaskCompletionSource.TrySetUnwrappedException方法代码示例

本文整理汇总了C#中TaskCompletionSource.TrySetUnwrappedException方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.TrySetUnwrappedException方法的具体用法?C# TaskCompletionSource.TrySetUnwrappedException怎么用?C# TaskCompletionSource.TrySetUnwrappedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaskCompletionSource的用法示例。


在下文中一共展示了TaskCompletionSource.TrySetUnwrappedException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WorkImpl

        private void WorkImpl(TaskCompletionSource<object> taskCompletionSource)
        {
        Process:
            if (!Alive)
            {
                // If this subscription is dead then return immediately
                taskCompletionSource.TrySetResult(null);
                return;
            }

            var items = new List<ArraySegment<Message>>();
            int totalCount;
            object state;

            PerformWork(items, out totalCount, out state);

            if (items.Count > 0)
            {
                var messageResult = new MessageResult(items, totalCount);
                Task<bool> callbackTask = Invoke(messageResult, s => BeforeInvoke(s), state);

                if (callbackTask.IsCompleted)
                {
                    try
                    {
                        // Make sure exceptions propagate
                        callbackTask.Wait();

                        if (callbackTask.Result)
                        {
                            // Sync path
                            goto Process;
                        }
                        else
                        {
                            // If we're done pumping messages through to this subscription
                            // then dispose
                            Dispose();

                            // If the callback said it's done then stop
                            taskCompletionSource.TrySetResult(null);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException is TaskCanceledException)
                        {
                            taskCompletionSource.TrySetCanceled();
                        }
                        else
                        {
                            taskCompletionSource.TrySetUnwrappedException(ex);
                        }
                    }
                }
                else
                {
                    WorkImplAsync(callbackTask, taskCompletionSource);
                }
            }
            else
            {
                taskCompletionSource.TrySetResult(null);
            }
        }
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:65,代码来源:Subscription.cs

示例2: WorkImplAsync

        private void WorkImplAsync(Task<bool> callbackTask, TaskCompletionSource<object> taskCompletionSource)
        {
            // Async path
            callbackTask.ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    taskCompletionSource.TrySetUnwrappedException(task.Exception);
                }
                else if (task.IsCanceled)
                {
                    taskCompletionSource.TrySetCanceled();
                }
                else if (task.Result)
                {
                    WorkImpl(taskCompletionSource);
                }
                else
                {
                    // If we're done pumping messages through to this subscription
                    // then dispose
                    Dispose();

                    // If the callback said it's done then stop
                    taskCompletionSource.TrySetResult(null);
                }
            });
        }
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:28,代码来源:Subscription.cs

示例3: ProcessMessages

        private Task ProcessMessages(ITransportConnection connection, Func<Task> postReceive)
        {
            var tcs = new TaskCompletionSource<object>();

            Action<Exception> endRequest = (ex) =>
            {
                Trace.TraceInformation("DrainWrites(" + ConnectionId + ")");

                // Drain the task queue for pending write operations so we don't end the request and then try to write
                // to a corrupted request object.
                WriteQueue.Drain().Catch().ContinueWith(task =>
                {
                    if (ex != null)
                    {
                        tcs.TrySetUnwrappedException(ex);
                    }
                    else
                    {
                        tcs.TrySetResult(null);
                    }

                    CompleteRequest();

                    Trace.TraceInformation("EndRequest(" + ConnectionId + ")");
                },
                TaskContinuationOptions.ExecuteSynchronously);

                if (AfterRequestEnd != null)
                {
                    AfterRequestEnd();
                }
            };

            ProcessMessages(connection, postReceive, endRequest);

            return tcs.Task;
        }
开发者ID:Jozef89,项目名称:SignalR,代码行数:37,代码来源:ForeverTransport.cs


注:本文中的TaskCompletionSource.TrySetUnwrappedException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。