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


C# this.ContinueWith方法代码示例

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


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

示例1: ExecuteContinueWithInternal

        public static void ExecuteContinueWithInternal(this Task task,Action successAction,Action exceptionAction,
            Action cancellationAction)
        {
            task.ContinueWith(p => successAction(),
                TaskContinuationOptions.OnlyOnRanToCompletion);

            task.ContinueWith(p => exceptionAction(), TaskContinuationOptions.NotOnFaulted);

            task.ContinueWith(p => cancellationAction(),
                              TaskContinuationOptions.OnlyOnCanceled);
        }
开发者ID:Hdesai,项目名称:XBuildLight,代码行数:11,代码来源:TaskExtensions.cs

示例2: AsAsyncResult

        /// <summary>
        /// A helper method for mocking APM (classic) asynchronous methods with on TAP (modern) asynchronous methods.
        /// </summary>
        /// <remarks>
        /// This is based on <a href="http://blogs.msdn.com/b/pfxteam/archive/2011/06/27/10179452.aspx"/> 
        /// and <a href="http://msdn.microsoft.com/en-us/library/hh873178.aspx"/>.
        /// </remarks>
        public static IAsyncResult AsAsyncResult(this Task task, AsyncCallback callback, object state)
        {
            Debug.Assert(task != null, "task");

            var taskCompletionSource = new TaskCompletionSource<object>(state);
            task.ContinueWith(
                t =>
                {
                    if (t.IsFaulted)
                    {
                        taskCompletionSource.TrySetException(t.Exception.InnerExceptions);
                    }
                    else if (t.IsCanceled)
                    {
                        taskCompletionSource.TrySetCanceled();
                    }
                    else
                    {
                        taskCompletionSource.SetResult(null);
                    }

                    if (callback != null)
                    {
                         callback(taskCompletionSource.Task);
                    }
                },
                TaskScheduler.Default);

            return taskCompletionSource.Task;
        }
开发者ID:bitstadium,项目名称:HockeySDK-Windows,代码行数:37,代码来源:TaskExtensions.cs

示例3: ToApm

		internal static Task ToApm(this Task task, AsyncCallback callback, object state) {
			if (task == null) {
				throw new ArgumentNullException("task");
			}

			var tcs = new TaskCompletionSource<object>(state);
			task.ContinueWith(
				t => {
					if (t.IsFaulted) {
						tcs.TrySetException(t.Exception.InnerExceptions);
					} else if (t.IsCanceled) {
						tcs.TrySetCanceled();
					} else {
						tcs.TrySetResult(null);
					}

					if (callback != null) {
						callback(tcs.Task);
					}
				},
				CancellationToken.None,
				TaskContinuationOptions.None,
				TaskScheduler.Default);

			return tcs.Task;
		}
开发者ID:jiowei,项目名称:dotnetopenid,代码行数:26,代码来源:Extensions.cs

示例4: IgnoreExceptions

 // The unobserved task handler extention. simply  observes the exception and do nothing.
 public static Task IgnoreExceptions(this Task task)
 {
     task.ContinueWith(c => { var ignored = c.Exception; },
         TaskContinuationOptions.OnlyOnFaulted |
         TaskContinuationOptions.ExecuteSynchronously);
     return task;
 }
开发者ID:hazelcast,项目名称:hazelcast-csharp-client,代码行数:8,代码来源:TaskExtension.cs

示例5: ToApm

		/// <summary>
		/// A Task extension method that converts this object to an IAsyncResult.
		/// </summary>
		/// <remarks>
		/// Mark, 19/06/2012.
		/// Props to Stephen Toub for this blog post:
		/// http://blogs.msdn.com/b/pfxteam/archive/2011/06/27/10179452.aspx
		/// </remarks>
		/// <param name="task"> The task to act on.</param>
		/// <param name="callback">The callback.</param>
		/// <param name="state">The state.</param>
		/// <returns>
		/// The given data converted to an IAsyncResult-y Task.
		/// </returns>
		public static Task ToApm(this Task task, AsyncCallback callback, object state)
		{
			task = task ?? MakeCompletedTask();
			var tcs = new TaskCompletionSource<object>();
			task.ContinueWith(t =>
			{
				if (t.IsFaulted)
				{
					tcs.TrySetException(t.Exception.InnerExceptions);
				}
				else if (t.IsCanceled)
				{
					tcs.TrySetCanceled();
				}
				else
				{
					tcs.TrySetResult(null);
				}

				if (callback != null)
				{
					callback(tcs.Task);
				}
			}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default);
			return tcs.Task;
		}
开发者ID:ChristopherMeek,项目名称:Simple.Web,代码行数:40,代码来源:TaskEx.cs

示例6: Forget

 public static void Forget(this Task task)
 {
     task.ContinueWith(t =>
     {
         var e = t.Exception;
     });
 }
开发者ID:rrawla,项目名称:dotnetConf2014,代码行数:7,代码来源:TaskExtensions.cs

示例7: Forget

 public static void Forget(this Task task)
 {
     task.ContinueWith(t =>
     {
         Debugger.Break();
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:bcjobs,项目名称:infra,代码行数:7,代码来源:TaskHelpers.cs

示例8: LogOnException

 public static void LogOnException(this Task task)
 {
     task.ContinueWith(t =>
         {
             Log.Error("Exception thrown in task started with LogOnException()", t.Exception);
         },
         TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:cpriebe,项目名称:MPExtended,代码行数:8,代码来源:TaskExtensionMethods.cs

示例9: Ignore

        public static void Ignore(this Task task)
        {
            Contract.Requires(task != null);

            // ReSharper disable CSharpWarnings::CS4014
            task.ContinueWith(t => t.Exception, TaskContinuationOptions.OnlyOnFaulted);
            // ReSharper restore CSharpWarnings::CS4014
        }
开发者ID:ExRam,项目名称:ExRam.Extensions,代码行数:8,代码来源:TaskExtensions+(Ignore).cs

示例10: Catch

 public static Task Catch(this Task task)
 {
     return task.ContinueWith(t =>
     {
         if (t.Exception != null)
             t.Exception.Handle(OnException);
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:greeduomacro,项目名称:UOInterface,代码行数:8,代码来源:Client.cs

示例11: OnExceptions

 /// <summary>
 /// Observes any exceptions thrown by a task and performs an Action on them. (ie: logging). This does not occur on task cancellation. Recommended that you iterate over AggregateException.InnerExceptions in this.
 /// </summary>
 /// <param name="task"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public static Task OnExceptions(this Task task, Action<AggregateException> action)
 {
     task.ContinueWith(t =>
     {
         action(t.Exception.Flatten());
     }, TaskContinuationOptions.OnlyOnFaulted);
     return task;
 }
开发者ID:rossmurray,项目名称:FileMonitor,代码行数:14,代码来源:TaskExtensions.cs

示例12: WaitWithPumping

 public static void WaitWithPumping(this Task task)
 {
     if (task == null) throw new ArgumentNullException("task");
     var nestedFrame = new DispatcherFrame();
     task.ContinueWith(_ => nestedFrame.Continue = false);
     Dispatcher.PushFrame(nestedFrame);
     task.Wait();
 }
开发者ID:Robin--,项目名称:raml-dotnet-tools,代码行数:8,代码来源:TaskExtensions.cs

示例13: Wait

        public static void Wait(this Task t)
        {
            var e = new System.Threading.ManualResetEvent(false);

            t.ContinueWith(_ => e.Set());

            e.WaitOne();
        }
开发者ID:endo0407,项目名称:IteratorTasks,代码行数:8,代码来源:TaskExtensions.cs

示例14: FailFastOnException

 public static Task FailFastOnException(this Task task)
 {
     task.ContinueWith(c =>
         Environment.FailFast(
             "An unhandled exception occurred in a background task",  c.Exception),
         TaskContinuationOptions.OnlyOnFaulted |  TaskContinuationOptions.ExecuteSynchronously);
     return task;
 }
开发者ID:GeeksDiary,项目名称:Molecules,代码行数:8,代码来源:TaskUtilities.cs

示例15: FireAndForget

 public static void FireAndForget(this Task task,string taskName,Action<Task> errorHandler=null)
 {
     if (errorHandler == null)
     {
         errorHandler = t => taskName.LogError(t.Exception);
     }
     task.ContinueWith(errorHandler, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:geffzhang,项目名称:cavemantools,代码行数:8,代码来源:Threading.cs


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