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


C# TaskCreationOptions类代码示例

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


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


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