• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TaskCreationOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Start

        /// <summary>
        /// Starts the periodic task.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="intervalInMilliseconds">The interval in milliseconds.</param>
        /// <param name="delayInMilliseconds">The delay in milliseconds, i.e. how long it waits to kick off the timer.</param>
        /// <param name="duration">The duration.
        /// <example>If the duration is set to 10 seconds, the maximum time this task is allowed to run is 10 seconds.</example></param>
        /// <param name="maxIterations">The max iterations.</param>
        /// <param name="synchronous">if set to <c>true</c> executes each period in a blocking fashion and each periodic execution of the task
        /// is included in the total duration of the Task.</param>
        /// <param name="cancelToken">The cancel token.</param>
        /// <param name="periodicTaskCreationOptions"><see cref="TaskCreationOptions"/> used to create the task for executing the <see cref="Action"/>.</param>
        /// <returns>A <see cref="Task"/></returns>
        /// <remarks>
        /// Exceptions that occur in the <paramref name="action"/> need to be handled in the action itself. These exceptions will not be 
        /// bubbled up to the periodic task.
        /// </remarks>
        public static Task Start(Action action,
                                 int intervalInMilliseconds = Timeout.Infinite,
                                 int delayInMilliseconds = 0,
                                 int duration = Timeout.Infinite,
                                 int maxIterations = -1,
                                 bool synchronous = false,
                                 CancellationToken cancelToken = new CancellationToken(),
                                 TaskCreationOptions periodicTaskCreationOptions = TaskCreationOptions.None)
        {
            Stopwatch stopWatch = new Stopwatch();
            Action wrapperAction = () =>
            {
                CheckIfCancelled(cancelToken);
                action();
            };

            Action mainAction = () =>
            {
                try
                {
                    MainPeriodicTaskAction(intervalInMilliseconds, delayInMilliseconds, duration, maxIterations,
                                           cancelToken, stopWatch, synchronous, wrapperAction,
                                           periodicTaskCreationOptions);
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception exception)
                {
                    throw;
                }
            };

            return Task.Factory.StartNew(mainAction, cancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
        }
开发者ID:KernelNO,项目名称:BFH-Rcon-Admin,代码行数:53,代码来源:PeriodicTaskFactory.cs


示例2: Iterate

 /// <summary>Asynchronously iterates through an enumerable of tasks.</summary>
 /// <param name="factory">The target factory.</param>
 /// <param name="source">The enumerable containing the tasks to be iterated through.</param>
 /// <param name="cancellationToken">The cancellation token used to cancel the iteration.</param>
 /// <param name="creationOptions">Options that control the task's behavior.</param>
 /// <param name="scheduler">The scheduler to which tasks will be scheduled.</param>
 /// <returns>A Task that represents the complete asynchronous operation.</returns>
 public static Task Iterate(
     this TaskFactory factory,
     IEnumerable<object> source,
     CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
 {
     return Iterate(factory, source, null, cancellationToken, creationOptions, scheduler);
 }
开发者ID:Farfeght,项目名称:parallel-extensions-extras,代码行数:14,代码来源:TaskFactoryExtensions_Iterate.cs


示例3: ContinuationTaskFromTask

 public ContinuationTaskFromTask(Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions)
     : base(action, state, InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, antecedent.Scheduler)
 {
     Contract.Requires(action is Action<Task> || action is Action<Task, object>, "Invalid delegate type in ContinuationTaskFromTask");
     _antecedent = antecedent;
     CapturedContext = ExecutionContext.Capture();
 }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:7,代码来源:ContinuationTaskFromTask.cs


示例4: CreateAndExecuteTaskContinueWith

 public static Task CreateAndExecuteTaskContinueWith(Action BodyMethod, Action ContinueMethod, TaskCreationOptions t_Options = TaskCreationOptions.None)
 {
     Task t_task = new Task(BodyMethod, t_Options);
     t_task.ContinueWith(_ => ContinueMethod);
     t_task.Start();
     return t_task;
 }
开发者ID:sreenandini,项目名称:test_buildscripts,代码行数:7,代码来源:TaskHelper.cs


示例5: Run

        /// <summary>
        /// Runs the specified task.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <param name="taskOption">The task option.</param>
        /// <param name="exceptionHandler">The exception handler.</param>
        /// <returns></returns>
        public static Task Run(Action task, TaskCreationOptions taskOption, Action<Exception> exceptionHandler)
        {

            return Task.Factory.StartNew(task, taskOption).ContinueWith(t =>
                {
                    exceptionHandler(t.Exception.InnerException);
                }, TaskContinuationOptions.OnlyOnFaulted);
        }
开发者ID:liutao51341,项目名称:Aton.AtonSocket,代码行数:15,代码来源:AsyncUtility.cs


示例6: Iterate

 /// <summary>Asynchronously iterates through an enumerable of tasks.</summary>
 /// <param name="factory">The target factory.</param>
 /// <param name="source">The enumerable containing the tasks to be iterated through.</param>
 /// <param name="creationOptions">Options that control the task's behavior.</param>
 /// <returns>A Task that represents the complete asynchronous operation.</returns>
 public static Task Iterate(
     this TaskFactory factory,
     IEnumerable<object> source, 
     TaskCreationOptions creationOptions)
 {
     if (factory == null) throw new ArgumentNullException("factory");
     return Iterate(factory, source, null, factory.CancellationToken, creationOptions, factory.GetTargetScheduler());
 }
开发者ID:bevacqua,项目名称:Swarm,代码行数:13,代码来源:TaskFactoryExtensions_Iterate.cs


示例7: AddDenyChildAttach

        public static TaskCreationOptions AddDenyChildAttach(TaskCreationOptions options)
        {
#if NET4
            options &= ~TaskCreationOptions.AttachedToParent;
            return options;
#else
            return options | TaskCreationOptions.DenyChildAttach;
#endif
        }
开发者ID:Nucs,项目名称:nlib,代码行数:9,代码来源:AsyncEnlightenment.cs


示例8: EsuTimerBase

 protected EsuTimerBase(int hour, int minute, int second, int interval, TaskCreationOptions creationOptions)
 {
     this.hour = hour;
       this.minute = minute;
       this.second = second;
       this.interval = interval;
       this.creationOptions = creationOptions;
       displayFormat = "mm:ss";
 }
开发者ID:EinsteinSu,项目名称:EsuCommon,代码行数:9,代码来源:EsuTimerBase.cs


示例9: Run

 public static Task Run(Action<object> task, object state, TaskCreationOptions taskOption, Action<Exception> exceptionHandler)
 {
     return Task.Factory.StartNew(task, state, taskOption).ContinueWith(t =>
     {
         if (exceptionHandler != null)
             exceptionHandler(t.Exception);
         else
             LogUtil.LogError(t.Exception);
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:10,代码来源:Async.cs


示例10: Run

 /// <summary>
 /// Runs the specified task.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="taskOption">The task option.</param>
 /// <param name="exceptionHandler">The exception handler.</param>
 /// <returns></returns>
 public static Task Run(Action task, TaskCreationOptions taskOption, Action<Exception> exceptionHandler)
 {
     return Task.Factory.StartNew(task, taskOption).ContinueWith(t =>
         {
             if (exceptionHandler != null)
                 exceptionHandler(t.Exception.InnerException);
             else
                 LogFactoryProvider.GlobalLog.Error(t.Exception.InnerException);
         }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:17,代码来源:Async.cs


示例11: ProducerConsumerQueue

        public ProducerConsumerQueue(int workerCount, TaskCreationOptions taskCreationOptions = TaskCreationOptions.None)
        {
            workerCount = Math.Max(1, workerCount);

            m_Workers = new Task[workerCount];
            for (int i = 0; i < workerCount; i++)
            {
                m_Workers[i] = Task.Factory.StartNew(Consume, taskCreationOptions);
            }
        }
开发者ID:NickJoosens,项目名称:net-ppwcode-util-oddsandends,代码行数:10,代码来源:ProducerConsumerQueue.cs


示例12: StartNewDelayed

        public static Task StartNewDelayed(this TaskFactory factory, int millisecondsDelay, Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) {
            if (factory == null)
                throw new ArgumentNullException(nameof(factory));
            if (millisecondsDelay < 0)
                throw new ArgumentOutOfRangeException(nameof(millisecondsDelay));
            if (action == null)
                throw new ArgumentNullException(nameof(action));
            if (scheduler == null)
                throw new ArgumentNullException(nameof(scheduler));

            return factory.StartNewDelayed(millisecondsDelay, cancellationToken).ContinueWith(_ => action(), cancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, scheduler);
        }
开发者ID:geffzhang,项目名称:Foundatio,代码行数:12,代码来源:TaskFactoryExtensions.cs


示例13: OnInterval

 public static Task OnInterval(TimeSpan pollInterval, Action action, CancellationToken token,
     TaskCreationOptions taskCreationOptions, TaskScheduler taskScheduler)
 {
     return Task.Factory.StartNew(() =>
     {
         for (;;)
         {
             if (token.WaitCancellationRequested(pollInterval))
                 break;
             action();
         }
     }, token, taskCreationOptions, taskScheduler);
 }
开发者ID:merbla,项目名称:amazingpaymentgateway,代码行数:13,代码来源:RepeatAction.cs


示例14: Run

        public static Task Run(Action a, TaskCreationOptions creationOptions = TaskCreationOptions.None)
        {
            var task = new Task(a, creationOptions);
            task.ContinueWith(t => { lock (m_runningTasks) m_runningTasks.Remove(t); });

            lock (m_runningTasks)
            {
                m_runningTasks.Add(task);
            }

            task.Start();
            return task;
        }
开发者ID:stefan-maierhofer-vrvis,项目名称:p.pro,代码行数:13,代码来源:TrackableTask.cs


示例15: Run

		public static Task Run(Action<ILifetimeScope> action, CancellationToken cancellationToken, TaskCreationOptions options, TaskScheduler scheduler)
		{
			Guard.ArgumentNotNull(() => action);
			Guard.ArgumentNotNull(() => scheduler);

			var t = Task.Factory.StartNew(() => {
				using (var container = EngineContext.Current.ContainerManager.Container.BeginLifetimeScope(AutofacLifetimeScopeProvider.HttpRequestTag))
				{
					action(container);
				}
			}, cancellationToken, options, scheduler);

			return t;
		}
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:14,代码来源:AsyncRunner.cs


示例16: CreateLongRunningThreadOptimized

        private Task CreateLongRunningThreadOptimized(int durationInMilliSecond, TaskCreationOptions taskCreationOptions)
        {
            Task t = Task.Factory.StartNew(() =>
            {
                //("task Started ...\n");

                var sw = System.Diagnostics.Stopwatch.StartNew();

                while (sw.ElapsedMilliseconds < durationInMilliSecond) ;
                //("Task Finished\n");
            },
            taskCreationOptions);

            return t;
        }
开发者ID:saeidghoreshi,项目名称:partition1,代码行数:15,代码来源:DesignPatterns2.cs


示例17: AsyncRun

 public static Task AsyncRun(Action<object> task, object state, TaskCreationOptions taskOption, Action<Exception> exceptionHandler)
 {
     return Task.Factory.StartNew(task, state, taskOption).ContinueWith(t =>
     {
         if (exceptionHandler != null)
             exceptionHandler(t.Exception);
         else
         {
             for (var i = 0; i < t.Exception.InnerExceptions.Count; i++)
             {
                 Console.WriteLine(t.Exception.InnerExceptions[i].Message);
             }
         }
     }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:iraychen,项目名称:LCLFramework,代码行数:15,代码来源:Async40.cs


示例18: AsyncRun

 /// <summary>
 /// Runs the specified task.
 /// </summary>
 /// <param name="logProvider">The log provider.</param>
 /// <param name="task">The task.</param>
 /// <param name="taskOption">The task option.</param>
 /// <param name="exceptionHandler">The exception handler.</param>
 /// <returns></returns>
 public static Task AsyncRun(this ILoggerProvider logProvider, Action task, TaskCreationOptions taskOption, Action<Exception> exceptionHandler)
 {
     return Task.Factory.StartNew(task, taskOption).ContinueWith(t =>
         {
             if (exceptionHandler != null)
                 exceptionHandler(t.Exception);
             else
             {
                 if (logProvider.Logger.IsErrorEnabled)
                 {
                     for (var i = 0; i < t.Exception.InnerExceptions.Count; i++)
                     {
                         logProvider.Logger.Error(t.Exception.InnerExceptions[i]);
                     }
                 }
             }
         }, TaskContinuationOptions.OnlyOnFaulted);
 }
开发者ID:huodianyan,项目名称:SuperSocket,代码行数:26,代码来源:Async.cs


示例19: ExecutorTaskAction

        private static void ExecutorTaskAction(Action action,
                                int interval,
                                int delay,
                                int runTime,
                                int maxRuns,
                                Stopwatch sw,
                                CancellationToken cancelToken = new CancellationToken(),
                                TaskCreationOptions taskOptions = TaskCreationOptions.None)
        {
            TaskCreationOptions taskCreationOptions = TaskCreationOptions.AttachedToParent | taskOptions;
            StopIfCancelled(cancelToken);
            if (delay > 0)
            {
                Thread.Sleep(delay);
            }
            if (maxRuns == 0) return;

            long iteration = 0;
            using (ManualResetEventSlim resetEvent = new ManualResetEventSlim(false))
            {
                while (true)
                {
                    StopIfCancelled(cancelToken);
                    Task subTask = Task.Factory.StartNew(action, cancelToken, taskCreationOptions, TaskScheduler.Current);

                    if (interval == Timeout.Infinite) { break; }

                    if (maxRuns > 0 && ++iteration >= maxRuns) { break; }

                    try
                    {
                        sw.Start();
                        resetEvent.Wait(interval, cancelToken);
                        sw.Stop();
                    }
                    finally
                    {
                        resetEvent.Reset();
                    }
                    StopIfCancelled(cancelToken);
                    if (runTime > 0 && sw.ElapsedMilliseconds >= runTime) { break; }
                }
            }
        }
开发者ID:cchamplin,项目名称:FFRest,代码行数:44,代码来源:TaskExecutorFactory.cs


示例20: Fall

            public bool Fall(int level, Token token, Params param, TaskCreationOptions taskCreationOptions = TaskCreationOptions.None)
            {
                lock (this)
                {
                    WaitFall();

                    if (token != null)
                    {
                        if (token.Cancellation.IsCancellationRequested)
                            return false;

                        token.CountdownEvent.AddCount(1);
                    }

                    bool haveSink = false;
                    BranchCache cache = null;
                    if (param.Sink)
                    {
                        if (Cache.OperationCount > 0)
                        {
                            if (param.IsTotal)
                            {
                                cache = Cache;
                                Cache = new BranchCache();
                                haveSink = true;
                            }
                            else //no matter IsOverall or IsPoint, we exclude all the operations for the path
                            {
                                IOperationCollection operationCollection = Cache.Exclude(param.Path);
                                if (operationCollection != null)
                                {
                                    cache = new BranchCache(/*param.Path,*/ operationCollection);
                                    haveSink = true;
                                }
                            }
                        }
                    }

                    Tree.WorkingFallCount.Increment();
                    FallTask = Task.Factory.StartNew(DoFall, new Tuple<Branch, BranchCache, int, Token, Params>(this, cache, level - 1, token, param), taskCreationOptions);

                    return haveSink;
                }
            }
开发者ID:KSLcom,项目名称:STSdb4,代码行数:44,代码来源:WTree.Branch.Fall.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TaskDialog类代码示例发布时间:2022-05-24
下一篇:
C# TaskCompletionSource类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap