當前位置: 首頁>>代碼示例>>C#>>正文


C# AggregateException類代碼示例

本文整理匯總了C#中AggregateException的典型用法代碼示例。如果您正苦於以下問題:C# AggregateException類的具體用法?C# AggregateException怎麽用?C# AggregateException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AggregateException類屬於命名空間,在下文中一共展示了AggregateException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ThrowAsync

        /// <summary>Throws the exception on the thread pool.</summary>
        /// <param name="exception">The exception to propagate.</param>
        /// <param name="targetContext">
        /// The target context on which to propagate the exception; otherwise, <see langword="null"/> to use the thread
        /// pool.
        /// </param>
        internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
        {
            if (targetContext != null)
            {
                try
                {
                    targetContext.Post(
                        state =>
                        {
                            throw PrepareExceptionForRethrow((Exception)state);
                        }, exception);
                    return;
                }
                catch (Exception ex)
                {
                    exception = new AggregateException(exception, ex);
                }
            }

#if NET45PLUS
            Task.Run(() =>
            {
                throw PrepareExceptionForRethrow(exception);
            });
#else
            ThreadPool.QueueUserWorkItem(state =>
            {
                throw PrepareExceptionForRethrow((Exception)state);
            }, exception);
#endif
        }
開發者ID:endo0407,項目名稱:IteratorTasks,代碼行數:37,代碼來源:AsyncServices.cs

示例2: ThrowAsync

		internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
		{
			if (targetContext != null)
			{
				try
				{
					targetContext.Post(delegate(object state)
					{
						throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
					}, exception);
					return;
				}
				catch (Exception ex)
				{
					exception = new AggregateException(new Exception[]
					{
						exception,
						ex
					});
				}
			}
			ThreadPool.QueueUserWorkItem(delegate(object state)
			{
				throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
			}, exception);
		}
開發者ID:tommybiteme,項目名稱:X,代碼行數:26,代碼來源:AsyncServices.cs

示例3: LogException

 /// <summary>
 /// Function to log exception except disposed exception.
 /// </summary>
 /// <param name="aggregateException">Aggregate Exception</param>
 private static void LogException(AggregateException aggregateException)
 {
     if (aggregateException != null)
     {
         aggregateException.Handle((ex) => HandleException(ex));
     }
 }
開發者ID:JaipurAnkita,項目名稱:mastercode,代碼行數:11,代碼來源:TimerExtensions.cs

示例4: HandleError

 private void HandleError(AggregateException ae)
 {
     if (ae.InnerException != null)
     {
         MessageBox.Show("An error occurred while uploading the image to imgur.com. Please try again.", "SnagitImgur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         ae.InnerException.ToExceptionless().Submit();
     }
 }
開發者ID:ebmp19,項目名稱:SnagitImgur,代碼行數:8,代碼來源:ShareController.cs

示例5: HandleAggregateException

        Tuple<string, bool> HandleAggregateException(AggregateException aggregrateException,
            ReportExceptionEventArgs et) {
            Tuple<string, bool> handled = null;
            foreach (var error in aggregrateException.Flatten().InnerExceptions) {
                if (handled == null || handled.Item1 == null)
                    handled = InternalHandler(error, et); // Does not set the loader to true
            }

            return handled;
        }
開發者ID:MaHuJa,項目名稱:withSIX.Desktop,代碼行數:10,代碼來源:KnownExceptions.cs

示例6: HandleFault

        public void HandleFault(AggregateException ex)
        {
            Logger.Error(ex.Message, ex);

            var message = IoC.Get<MessageBoxViewModel>();
            message.DisplayName = "Error";
            message.Content = new ErrorInfo();
            message.DismissAction = () => NavigateToHome();
            message.DismissTimeout = 10000;

            NavigateToScreen(message);
        }
開發者ID:edjo23,項目名稱:shop,代碼行數:12,代碼來源:ScreenCoordinator.cs

示例7: HandleException

 private static void HandleException(AggregateException ex)
 {
     if (ex.InnerExceptions.OfType<TaskCanceledException>()
           .Any())
     {
         Console.WriteLine("Task was canceled...");
         Log.Trace("Task was canceled");
     }
     else
     {
         Log.Error(ex, "Task proccessing exception");
     }
 }
開發者ID:matafonoff,項目名稱:Brokeree.Test,代碼行數:13,代碼來源:Program.cs

示例8: SimpleInnerExceptionTestCase

		public void SimpleInnerExceptionTestCase ()
		{
			var message = "Foo";
			var inner = new ApplicationException (message);
			var ex = new AggregateException (inner);

			Assert.IsNotNull (ex.InnerException);
			Assert.IsNotNull (ex.InnerExceptions);

			Assert.AreEqual (inner, ex.InnerException);
			Assert.AreEqual (1, ex.InnerExceptions.Count);
			Assert.AreEqual (inner, ex.InnerExceptions[0]);
			Assert.AreEqual (message, ex.InnerException.Message);
		}
開發者ID:bradchen,項目名稱:mono,代碼行數:14,代碼來源:AggregateExceptionTests.cs

示例9: EventForFailedOperation

        internal static IProvisioningEvent EventForFailedOperation(AggregateException exception)
        {
            HttpStatusCode httpStatus;
            if (ProvisioningErrorHandling.TryGetHttpStatusCode(exception, out httpStatus))
            {
                return ProvisioningErrorHandling.IsTransientError(exception)
                    ? (IProvisioningEvent)new DiscoveryFailedTransientEvent(exception, httpStatus)
                    : new DiscoveryFailedPermanentEvent(exception, httpStatus);
            }

            return ProvisioningErrorHandling.IsTransientError(exception)
                ? (IProvisioningEvent)new DiscoveryFailedTransientEvent(exception)
                : new DiscoveryFailedPermanentEvent(exception);
        }
開發者ID:TeamKnowledge,項目名稱:lokad-cloud-provisioning,代碼行數:14,代碼來源:AzureDiscovery.cs

示例10: Start

        public void Start()
        {
            m_InstanciedServiceList = new List<object>();
            var list = GetServiceTypeList();
            System.Diagnostics.Trace.WriteLine(string.Format("{0} services found", list.Count()));
            m_ServiceList = list.Where(i => !i.Item1).Select(i => Type.GetType(i.Item2)).ToList();
            var autoUpdateServiceHostList = list.Where(i => i.Item1).Select(i => i.Item2).ToList();

            var failList = new List<Exception>();
            StartServices(failList);
            if (failList.Count > 0)
            {
                var failStartException = new AggregateException("Start services failed", failList);
                throw failStartException;
            }
        }
開發者ID:chouteau,項目名稱:palace,代碼行數:16,代碼來源:Starter.cs

示例11: GetMessageAndStackTrace

        public static String GetMessageAndStackTrace(AggregateException e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e", "AggregateException can not be null.");
            }

            var sb = new StringBuilder();

            foreach (Exception innerException in e.InnerExceptions)
            {
                sb.AppendLine(innerException.Message);
                sb.AppendLine("\t" + innerException.StackTrace);
            }

            return sb.ToString();
        }
開發者ID:gnikolaropoulos,項目名稱:.Net-Labs,代碼行數:17,代碼來源:ExceptionServices.cs

示例12: ThrowAsync

        /// <summary>Throws the exception on the ThreadPool.</summary>
        /// <param name="exception">The exception to propagate.</param>
        /// <param name="targetContext">The target context on which to propagate the exception.  Null to use the ThreadPool.</param>
        internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
        {
            // If the user supplied a SynchronizationContext...
            if (targetContext != null)
            {
                try
                {
                    // Post the throwing of the exception to that context, and return.
                    targetContext.Post(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
                    return;
                }
                catch (Exception postException)
                {
                    // If something goes horribly wrong in the Post, we'll 
                    // propagate both exceptions on the ThreadPool
                    exception = new AggregateException(exception, postException);
                }
            }

            // Propagate the exception(s) on the ThreadPool
            ThreadPool.QueueUserWorkItem(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
        }
開發者ID:Dmk1k,項目名稱:referencesource,代碼行數:25,代碼來源:AsyncServices.cs

示例13: Exception

        public void Should_persist_and_unwrap_multiple_nested_original_exception_in_requestexecutionexception_with_exceptions_on_multiple_levels()
        {
            // Given
            var expectedException1 = new Exception();
            var expectedException2 = new Exception();
            var expectedException3 = new Exception();
            var expectedException4 = new Exception();
            var expectgedInnerExceptions = 4;
            var exceptionsListInner = new List<Exception>() { expectedException1, expectedException2, expectedException3 };
            var expectedExceptionInner = new AggregateException(exceptionsListInner);
            var exceptionsListOuter = new List<Exception>() { expectedExceptionInner, expectedException4 };
            var aggregateExceptionOuter = new AggregateException(exceptionsListOuter);

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            A.CallTo(() => this.requestDispatcher.Dispatch(context, A<CancellationToken>._))
                .Returns(TaskHelpers.GetFaultedTask<Response>(aggregateExceptionOuter));

            var pipelines = new Pipelines();
            pipelines.OnError.AddItemToStartOfPipeline((ctx, exception) => null);
            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            var result = this.engine.HandleRequest(request);
            var returnedException = result.Items["ERROR_EXCEPTION"] as RequestExecutionException;

            // Then
            var returnedInnerException = returnedException.InnerException as AggregateException;
            returnedInnerException.ShouldBeOfType(typeof(AggregateException));
            Assert.Equal(expectgedInnerExceptions, returnedInnerException.InnerExceptions.Count);
        }
開發者ID:ravindrapro,項目名稱:Nancy,代碼行數:40,代碼來源:NancyEngineFixture.cs

示例14: Should_persist_and_unwrap_original_exception_in_requestexecutionexception

        public void Should_persist_and_unwrap_original_exception_in_requestexecutionexception()
        {
            // Given
            var expectedException = new Exception();
            var aggregateException = new AggregateException(expectedException);

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            A.CallTo(() => this.requestDispatcher.Dispatch(context, A<CancellationToken>._))
                .Returns(TaskHelpers.GetFaultedTask<Response>(aggregateException));

            var pipelines = new Pipelines();
            pipelines.OnError.AddItemToStartOfPipeline((ctx, exception) => null);
            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            var result = this.engine.HandleRequest(request);
            var returnedException = result.Items["ERROR_EXCEPTION"] as RequestExecutionException;

            // Then
            returnedException.InnerException.ShouldBeSameAs(expectedException);
        }
開發者ID:ravindrapro,項目名稱:Nancy,代碼行數:31,代碼來源:NancyEngineFixture.cs

示例15: RealRun

        /// <summary>
        /// The method that performs the tests
        /// Depending on the inputs different test code paths will be exercised
        /// </summary>
        internal void RealRun()
        {
            TaskScheduler tm = TaskScheduler.Default;

            CreateTask(tm, _taskTree);
            // wait the whole task tree to be created 
            _countdownEvent.Wait();

            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                switch (_api)
                {
                    case API.Cancel:
                        _taskTree.CancellationTokenSource.Cancel();
                        break;

                    case API.Wait:
                        switch (_waitBy)
                        {
                            case WaitBy.None:
                                _taskTree.Task.Wait();
                                _taskCompleted = true;
                                break;
                            case WaitBy.Millisecond:
                                _taskCompleted = _taskTree.Task.Wait(_waitTimeout);
                                break;
                            case WaitBy.TimeSpan:
                                _taskCompleted = _taskTree.Task.Wait(new TimeSpan(0, 0, 0, 0, _waitTimeout));
                                break;
                        }
                        break;
                }
            }
            catch (AggregateException exp)
            {
                _caughtException = exp.Flatten();
            }
            finally
            {
                sw.Stop();
            }

            if (_waitTimeout != -1)
            {
                long delta = sw.ElapsedMilliseconds - ((long)_waitTimeout + s_deltaTimeOut);

                if (delta > 0)
                {
                    Debug.WriteLine("ElapsedMilliseconds way more than requested Timeout.");
                    Debug.WriteLine("WaitTime= {0} ms, ElapsedTime= {1} ms, Allowed Descrepancy = {2} ms", _waitTimeout, sw.ElapsedMilliseconds, s_deltaTimeOut);
                    Debug.WriteLine("Delta= {0} ms", delta);
                }
                else
                {
                    var delaytask = Task.Delay((int)Math.Abs(delta));  // give delay to allow Context being collected before verification
                    delaytask.Wait();
                }
            }

            Verify();
            _countdownEvent.Dispose();
        }
開發者ID:ChuangYang,項目名稱:corefx,代碼行數:68,代碼來源:TaskCancelWaitTest.cs


注:本文中的AggregateException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。