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


C# ExceptionServices.ExceptionDispatchInfo类代码示例

本文整理汇总了C#中System.Runtime.ExceptionServices.ExceptionDispatchInfo的典型用法代码示例。如果您正苦于以下问题:C# ExceptionDispatchInfo类的具体用法?C# ExceptionDispatchInfo怎么用?C# ExceptionDispatchInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionDispatchInfo类属于System.Runtime.ExceptionServices命名空间,在下文中一共展示了ExceptionDispatchInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnTimeoutExceptionAsync

        public async Task OnTimeoutExceptionAsync(ExceptionDispatchInfo exceptionInfo, TimeSpan timeoutGracePeriod)
        {
            FunctionTimeoutException timeoutException = exceptionInfo.SourceException as FunctionTimeoutException;

            if (timeoutException?.Task != null)
            {
                // We may double the timeoutGracePeriod here by first waiting to see if the iniital
                // function task that started the exception has completed.
                Task completedTask = await Task.WhenAny(timeoutException.Task, Task.Delay(timeoutGracePeriod));

                // If the function task has completed, simply return. The host has already logged the timeout.
                if (completedTask == timeoutException.Task)
                {
                    return;
                }
            }

            LogErrorAndFlush("A function timeout has occurred. Host is shutting down.", exceptionInfo.SourceException);

            // We can't wait on this as it may cause a deadlock if the timeout was fired
            // by a Listener that cannot stop until it has completed.
            Task ignoreTask = _manager.StopAsync();

            // Give the manager and all running tasks some time to shut down gracefully.
            await Task.Delay(timeoutGracePeriod);

            HostingEnvironment.InitiateShutdown();
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:28,代码来源:WebScriptHostExceptionHandler.cs

示例2: ExceptionContext

        /// <summary>
        /// Initializes a new instance of the <see cref="ExceptionContext"/> class using the values provided.
        /// </summary>
        /// <param name="exceptionInfo">The exception caught.</param>
        /// <param name="catchBlock">The catch block where the exception was caught.</param>
        /// <param name="context">The context in which the exception occurred.</param>
        public ExceptionContext(ExceptionDispatchInfo exceptionInfo, ExceptionContextCatchBlock catchBlock, CommandHandlerContext context)
        {
            if (exceptionInfo == null)
            {
                throw new ArgumentNullException("exceptionInfo");
            }

            this.ExceptionInfo = exceptionInfo;

            if (catchBlock == null)
            {
                throw new ArgumentNullException("catchBlock");
            }

            this.CatchBlock = catchBlock;

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.Context = context;

            CommandHandlerRequest request = context.Request;

            if (request == null)
            {
                throw Error.ArgumentNull(Resources.TypePropertyMustNotBeNull, typeof(HandlerRequest).Name, "Request", "context");
            }

            this.Request = request;
        }
开发者ID:ctguxp,项目名称:Waffle,代码行数:38,代码来源:ExceptionContext.cs

示例3: SignalFailure

 internal void SignalFailure(ExceptionDispatchInfo error)
 {
     if (_storedException == null)
     {
         _storedException = error;
     }
     SignalComplete();
 }
开发者ID:dmetzgar,项目名称:corefx,代码行数:8,代码来源:CurlResponseMessage.cs

示例4: EventHandlerOccurredContext

        /// <summary>
        /// Initializes a new instance of the <see cref="EventHandlerOccurredContext"/> class.
        /// </summary>
        /// <param name="handlerContext">Then handler context.</param>
        /// <param name="exceptionInfo">The <see cref="ExceptionDispatchInfo"/>. Optionnal.</param>
        public EventHandlerOccurredContext(EventHandlerContext handlerContext, ExceptionDispatchInfo exceptionInfo)
        {
            if (handlerContext == null)
            {
                throw Error.ArgumentNull("handlerContext");
            }

            this.handlerContext = handlerContext;
            this.ExceptionInfo = exceptionInfo;
        }
开发者ID:ctguxp,项目名称:Waffle,代码行数:15,代码来源:EventHandlerOccuredContext.cs

示例5: CommandHandlerExecutedContext

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandHandlerExecutedContext"/> class.
        /// </summary>
        /// <param name="handlerContext">Then handler context.</param>
        /// <param name="exceptionInfo">The <see cref="ExceptionDispatchInfo"/>. Optionnal.</param>
        public CommandHandlerExecutedContext(CommandHandlerContext handlerContext, ExceptionDispatchInfo exceptionInfo)
        {
            if (handlerContext == null)
            {
                throw Error.ArgumentNull("handlerContext");
            }

            this.ExceptionInfo = exceptionInfo;
            this.handlerContext = handlerContext;
        }
开发者ID:ctguxp,项目名称:Waffle,代码行数:15,代码来源:CommandHandlerExecutedContext.cs

示例6: HttpRouteExceptionHandler

        internal HttpRouteExceptionHandler(ExceptionDispatchInfo exceptionInfo,
            IExceptionLogger exceptionLogger, IExceptionHandler exceptionHandler)
        {
            Contract.Assert(exceptionInfo != null);
            Contract.Assert(exceptionLogger != null);
            Contract.Assert(exceptionHandler != null);

            _exceptionInfo = exceptionInfo;
            _exceptionLogger = exceptionLogger;
            _exceptionHandler = exceptionHandler;
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:11,代码来源:HttpRouteExceptionHandler.cs

示例7: Throw

        public void Throw(ExceptionDispatchInfo exceptionInfo)
        {
            Debug.Assert(exceptionInfo != null);

            Thread thread = new Thread(() =>
            {
                exceptionInfo.Throw();
            });
            thread.Start();
            thread.Join();
        }
开发者ID:rafaelmtz,项目名称:azure-webjobs-sdk,代码行数:11,代码来源:BackgroundExceptionDispatcher.cs

示例8: SetException

		public void SetException (AggregateException exception)
		{
#if NET_4_5			
			if (dispatchInfo == null) {
				//
				// Used by task awaiter to rethrow an exception with original call stack, it's
				// needed for first exception only
				//
				dispatchInfo = ExceptionDispatchInfo.Capture (exception.InnerException);
			}
#endif
			this.exception = exception;
		}
开发者ID:genoher,项目名称:mono,代码行数:13,代码来源:TaskExceptionSlot.cs

示例9: AllocException

        private IntPtr AllocException(Exception ex)
        {
            _lastException = ExceptionDispatchInfo.Capture(ex);

            string exString = ex.ToString();
            IntPtr nativeException = AllocException(exString, exString.Length);
            if (_nativeExceptions == null)
            {
                _nativeExceptions = new List<IntPtr>();
            }
            _nativeExceptions.Add(nativeException);
            return nativeException;
        }
开发者ID:stephentoub,项目名称:corert,代码行数:13,代码来源:CorInfoImpl.cs

示例10: CallCallbackPossiblyUnderLock

 private void CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) {
     ThreadContext threadContext = null;
     try {
         threadContext = _application.OnThreadEnter();
         try {
             callback(state);
         }
         catch (Exception e) {
             _error = ExceptionDispatchInfo.Capture(e);
         }
     }
     finally {
         if (threadContext != null) {
             threadContext.DisassociateFromCurrentThread();
         }
     }
 }
开发者ID:uQr,项目名称:referencesource,代码行数:17,代码来源:LegacyAspNetSynchronizationContext.cs

示例11: ThrowEntryPoint

 private static void ThrowEntryPoint()
 {
     if (s_EDI == null)
     {
         try
         {
             ThrowEntryPointInner();
         }
         catch(Exception ex)
         {
             Console.WriteLine("Caught exception with message: {0}", ex.Message);
             s_EDI = ExceptionDispatchInfo.Capture(ex);
         }
     }
     else
     {
         Console.WriteLine("s_Exception is not null!");
         s_EDI = null;
     }
 }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:20,代码来源:StackTracePreserveTests.cs

示例12: CheckRetryForExceptionAsync

        private async Task CheckRetryForExceptionAsync(ExceptionDispatchInfo ex, bool reinitialize)
        {
            if (simulator.AsyncRetryHandler == null)
            {
                // Simply rethrow the exception.
                ex.Throw();
            }
            else
            {
                // Need to release active keys etc.
                CancelActiveInteractions();

                bool result = await simulator.AsyncRetryHandler(ex);
                if (!result)
                    throw new SimulatorCanceledException();

                // When trying again, we need to re-initialize.
                if (reinitialize)
                    await InitializeAsync();
            }
        }
开发者ID:kpreisser,项目名称:MouseClickSimulator,代码行数:21,代码来源:StandardInteractionProvider.cs

示例13: Run

            /// <summary>
            /// Enqueues the function to be executed and executes all resulting continuations until it is completely done
            /// </summary>
            public void Run()
            {
                Post(async _ =>
                {
                    try
                    {
                        await _task();
                    }
                    catch (Exception exception)
                    {
                        _caughtException = ExceptionDispatchInfo.Capture(exception);
                        throw;
                    }
                    finally
                    {
                        Post(state => _done = true, null);
                    }
                }, null);

                while (!_done)
                {
                    Tuple<SendOrPostCallback, object> task;

                    if (_items.TryDequeue(out task))
                    {
                        task.Item1(task.Item2);

                        if (_caughtException == null) continue;

                        _caughtException.Throw();
                    }
                    else
                    {
                        _workItemsWaiting.WaitOne();
                    }
                }
            }
开发者ID:rebus-org,项目名称:Rebus,代码行数:40,代码来源:AsyncHelpers.cs

示例14: SetCancellationException

        /// <summary>Sets the cancellation exception.</summary>
        /// <param name="exceptionObject">The cancellation exception.</param>
        /// <remarks>
        /// Must be called under lock.
        /// </remarks>
        private void SetCancellationException(object exceptionObject)
        {
            Contract.Requires(exceptionObject != null, "Expected exceptionObject to be non-null.");

            Debug.Assert(m_cancellationException == null,
                "Expected SetCancellationException to be called only once.");
            // Breaking this assumption will overwrite a previously OCE,
            // and implies something may be wrong elsewhere, since there should only ever be one.

            Debug.Assert(m_faultExceptions == null,
                "Expected SetCancellationException to be called before any faults were added.");
            // Breaking this assumption shouldn't hurt anything here, but it implies something may be wrong elsewhere.
            // If this changes, make sure to only conditionally mark as handled below.

            // Store the cancellation exception
            var oce = exceptionObject as OperationCanceledException;
            if (oce != null)
            {
                m_cancellationException = ExceptionDispatchInfo.Capture(oce);
            }
            else
            {
                var edi = exceptionObject as ExceptionDispatchInfo;
                Debug.Assert(edi != null && edi.SourceException is OperationCanceledException,
                    "Expected an OCE or an EDI that contained an OCE");
                m_cancellationException = edi;
            }

            // This is just cancellation, and there are no faults, so mark the holder as handled.
            MarkAsHandled(false);
        }
开发者ID:adityamandaleeka,项目名称:corert,代码行数:36,代码来源:TaskExceptionHolder.cs

示例15: Start

        public async Task Start(IEnumerable<Task> tasks, CancellationTokenSource cancelSource)
        {
            if (tasks == null) throw new ArgumentNullException(nameof(tasks));
            if (cancelSource == null) throw new ArgumentNullException(nameof(cancelSource));

            while (true)
            {
                var task = _task;
                if (task != null)
                    await Stop().ConfigureAwait(false);

                using (await _lock.LockAsync().ConfigureAwait(false))
                {
                    _cancelSource = cancelSource;

                    if (_task != null)
                        continue; //Another thread sneaked in and started this manager before we got a lock, loop and try again

                    _stopReason = null;
                    WasStopExpected = false;

                    Task[] tasksArray = tasks.ToArray();

                    _task = Task.Run(async () =>
                    {
                        if (tasksArray.Length > 0)
                        {
                            Task<Task> anyTask = tasksArray.Length > 0 ? Task.WhenAny(tasksArray) : null;
                            Task allTasks = tasksArray.Length > 0 ? Task.WhenAll(tasksArray) : null;
                            //Wait for the first task to stop or error
                            Task firstTask = await anyTask.ConfigureAwait(false);

                            //Signal the rest of the tasks to stop
                            if (firstTask.Exception != null)
                                await SignalError(firstTask.Exception).ConfigureAwait(false);
                            else if (StopOnCompletion) //Unless we allow for natural completions
                                await SignalStop().ConfigureAwait(false);

                            //Wait for the other tasks, and signal their errors too just in case
                            try { await allTasks.ConfigureAwait(false); }
                            catch (AggregateException ex) { await SignalError(ex.InnerExceptions.First()).ConfigureAwait(false); }
                            catch (Exception ex) { await SignalError(ex).ConfigureAwait(false); }
                        }

                        if (!StopOnCompletion && !_cancelSource.IsCancellationRequested)
                        {
                            try { await Task.Delay(-1, _cancelSource.Token).ConfigureAwait(false); } //Pause until TaskManager is stopped
                            catch (OperationCanceledException) { }
                        }

                        //Run the cleanup function within our lock
                        if (_stopAction != null)
                            await _stopAction().ConfigureAwait(false);
                        _task = null;
                        _cancelSource = null;
                    });
                    return;
                }
            }
        }
开发者ID:Carbonitex,项目名称:Discord.Net,代码行数:60,代码来源:TaskManager.cs


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