/// <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); }
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; }
/// <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); }
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(); }
/// <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); }
/// <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()); }
public static TaskCreationOptions AddDenyChildAttach(TaskCreationOptions options) { #if NET4 options &= ~TaskCreationOptions.AttachedToParent; return options; #else return options | TaskCreationOptions.DenyChildAttach; #endif }
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"; }
/// <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); }
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); }
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); } }
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); }
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; }
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); }
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; }
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); }
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; }
/// <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); }
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; } }
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; } } } }
public static Task Begin(Action action, int interval = Timeout.Infinite, int delay = 0, int runTime = Timeout.Infinite, int maxRuns = -1, CancellationToken cancelToken = new CancellationToken(), TaskCreationOptions taskOptions = TaskCreationOptions.None) { Stopwatch sw = new Stopwatch(); Action wrapper = () => { StopIfCancelled(cancelToken); action(); }; Action executor = () => { ExecutorTaskAction(wrapper, interval, delay, runTime, maxRuns, sw, cancelToken, taskOptions); }; return Task.Factory.StartNew(executor, cancelToken, taskOptions, TaskScheduler.Current); }
public Task <TResult> StartNew <TResult>(Func <TResult> function, TaskCreationOptions creationOptions) { return(StartNew <TResult>(function, cancellationToken, creationOptions, GetScheduler())); }
public Task StartNew(Action <object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { Task t = new Task(action, state, cancellationToken, creationOptions); if (!t.IsCompleted) { t.Start(scheduler); } return(t); }
public AsyncLockSet( ReentryMode reentryMode, TaskCreationOptions taskCreationOptions = TaskCreationOptions.RunContinuationsAsynchronously) : this(reentryMode, taskCreationOptions, DefaultConcurrencyLevel, DefaultCapacity) { }
public NamedTask(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : base(action, cancellationToken, creationOptions) { }
public Task <TResult> StartNew <TResult>(Func <object, TResult> function, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { // Should not be static var result = new Task <TResult>(function, state, cancellationToken, creationOptions, scheduler); result.InternalStart(scheduler, false, true); return(result); }
public Task StartNew(Action <object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { // Should not be static var result = new Task(action, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, scheduler); result.InternalStart(scheduler, false, true); return(result); }
/// <summary> /// Creates a new TaskFactory /// </summary> public TaskFactory(TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions) : this(CancellationToken.None, creationOptions, continuationOptions, null) { }
public Task StartNew(Action action, TaskCreationOptions creationOptions) { return(StartNew(action, cancellationToken, creationOptions, GetScheduler())); }
public LeveledTask(Action<object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : base(action, state, cancellationToken, creationOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="TaskCompletionSource"/> class with the specified state and options. /// </summary> /// <param name="state">The state to use as the underlying <see cref="Task"/>'s <see cref="IAsyncResult.AsyncState"/>.</param> /// <param name="creationOptions">The options to use when creating the underlying <see cref="Task"/>.</param> public TaskCompletionSource(object state, TaskCreationOptions creationOptions) { _tcs = new TaskCompletionSource<object>(state, creationOptions); }
public LeveledTask(Action<object> action, object state, TaskCreationOptions creationOptions) : base(action, state, creationOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="TaskCompletionSource"/> class with the specified options. /// </summary> /// <param name="creationOptions">The options to use when creating the underlying <see cref="Task"/>.</param> public TaskCompletionSource(TaskCreationOptions creationOptions) { _tcs = new TaskCompletionSource <object>(creationOptions); }
/// <summary> /// Creates a <see cref="TaskCompletionSource{TResult}" /> with /// the specified state and options. /// </summary> /// <param name="state"> /// The state to use as the underlying /// <see cref="T:System.Threading.Tasks.Task{TResult}" />'s AsyncState. /// </param> /// <param name="creationOptions"> /// The options to use when creating the underlying /// <see cref="T:System.Threading.Tasks.Task{TResult}" />. /// </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The <paramref name="creationOptions" /> represent options invalid for use /// with a <see cref="TaskCompletionSource{TResult}" />. /// </exception> public TaskCompletionSource(object state, TaskCreationOptions creationOptions) { _task = new Task <TResult>(state, creationOptions); }
public NamedTask(Action <object> action, object state, TaskCreationOptions creationOptions) : base(action, state, creationOptions) { }
public TaskCompletionSource(TaskCreationOptions options) { _innerSource = new TaskCompletionSource<object>(options); }
public Task StartNew(Action <object> action, object state, TaskCreationOptions creationOptions) { return(StartNew(action, state, cancellationToken, creationOptions, GetScheduler())); }
public TaskSource(object state, TaskCreationOptions creationOptions) : base(state, creationOptions) { }
public void ReadAll(Func <int, Release, bool> processor) { TaskCreationOptions taskOptions = TaskCreationOptions.LongRunning; Task[] consumers = new Task[this.ThreadCount]; for (int i = 0; i < consumers.Length; ++i) { consumers[i] = Task.Factory.StartNew(delegate(object state) { int threadNumber = (int)state; int count = 0; try { string[] stringBatch; while (true) { BlockingCollection <string[]> .TakeFromAny(stringCollection, out stringBatch, cancellationToken); foreach (string releaseStringOriginal in stringBatch) { // Remove <releases>...</releases> string releaseString = Utility.TrimString(releaseStringOriginal, "<releases>"); releaseString = Utility.TrimString(releaseString, "</releases>"); var fixedText = Utility.FixXmlText(releaseString); XDocument doc = XDocument.Parse(fixedText); var release = DataReader.ReadRelease(doc.Root); ++count; if (!processor(threadNumber, release)) { cancellationSource.Cancel(); throw new OperationCanceledException(); } } } } catch (OperationCanceledException) { } catch (InvalidOperationException) { } catch (ArgumentException) { } }, i, taskOptions); } Task stringProducer = Task.Factory.StartNew(delegate { try { string[] stringBatch; while (ReadBatch(BatchSize, out stringBatch)) { BlockingCollection <string[]> .AddToAny(stringCollection, stringBatch, cancellationToken); } } catch (OperationCanceledException) { } catch (InvalidOperationException) { } finally { foreach (var coll in stringCollection) { coll.CompleteAdding(); } } }, taskOptions); Task dataReader = Task.Factory.StartNew(delegate { try { int read = 0; char[] NewBuffer = new char[BufferSize]; while ((read = reader.ReadBlock(NewBuffer, 0, BufferSize)) > 0) { bufferCollection.Add(new CharBuffer(NewBuffer, read), cancellationToken); NewBuffer = new char[BufferSize]; } } catch (OperationCanceledException) { } finally { bufferCollection.CompleteAdding(); } }, taskOptions); Task.WaitAll(consumers); stringProducer.Wait(); dataReader.Wait(); }
public NamedTask(Action <object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : base(action, state, cancellationToken, creationOptions) { }
public Task <TResult> StartNew <TResult>(Func <object, TResult> function, object state, TaskCreationOptions creationOptions) { var result = new Task <TResult>(function, state, CancellationToken.None, creationOptions, _scheduler); result.InternalStart(_scheduler, false, true); return(result); }
/// <summary> /// Modifies the specified flags to include RunContinuationsAsynchronously /// if wanted by the caller and supported by the platform. /// </summary> /// <param name="options">The base options supplied by the caller.</param> /// <param name="allowInliningContinuations"><c>true</c> to allow inlining continuations.</param> /// <returns>The possibly modified flags.</returns> private static TaskCreationOptions AdjustFlags(TaskCreationOptions options, bool allowInliningContinuations) { return((!allowInliningContinuations && LightUps.IsRunContinuationsAsynchronouslySupported) ? (options | LightUps.RunContinuationsAsynchronously) : options); }
public Task <TResult> StartNew <TResult>(Func <object, TResult> function, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { Task <TResult> t = new Task <TResult>(function, state, cancellationToken, creationOptions); if (!t.IsCompleted) { t.Start(scheduler); } return(t); }
public AsyncLockSet( TaskCreationOptions taskCreationOptions = TaskCreationOptions.RunContinuationsAsynchronously) : this(ReentryMode.CheckedFail, taskCreationOptions) { }
public Task <TResult> FromAsync(IAsyncResult asyncResult, Func <IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions) { return(FromAsync(asyncResult, endMethod, creationOptions, GetScheduler())); }
public Task <TResult> FromAsync(IAsyncResult asyncResult, Func <IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler) { return(FromIAsyncResult(asyncResult, endMethod, creationOptions, scheduler)); }
public TaskSource(TaskCreationOptions creationOptions) : base(creationOptions) { }
internal static Task <TResult> FromIAsyncResult(IAsyncResult asyncResult, Func <IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } if (endMethod == null) { throw new ArgumentNullException("endMethod"); } if (scheduler == null) { throw new ArgumentNullException("scheduler"); } if ((creationOptions & Task.WorkerTaskNotSupportedOptions) != 0) { throw new ArgumentOutOfRangeException("creationOptions"); } var source = new CancellationTokenSource(); var task = new Task <TResult> (l => { try { return(endMethod(asyncResult)); } catch (OperationCanceledException) { source.Cancel(); source.Token.ThrowIfCancellationRequested(); } return(default(TResult)); }, null, source.Token, creationOptions); // Take quick path for completed operations if (asyncResult.IsCompleted) { task.RunSynchronously(scheduler); } else { ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, (s, t) => task.RunSynchronously(scheduler), null, Timeout.Infinite, true); } return(task); }
/// <summary> /// Initializes a new instance of the <see cref="TaskCompletionSource"/> class with the specified state and options. /// </summary> /// <param name="state">The state to use as the underlying <see cref="Task"/>'s <see cref="IAsyncResult.AsyncState"/>.</param> /// <param name="creationOptions">The options to use when creating the underlying <see cref="Task"/>.</param> public TaskCompletionSource(object state, TaskCreationOptions creationOptions) { _tcs = new TaskCompletionSource <object>(state, creationOptions); }
public NamedTask(Action action, TaskCreationOptions creationOptions) : base(action, creationOptions) { }
public LeveledTask(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : base(action, cancellationToken, creationOptions) { }
public TaskCompletionSource(TaskCreationOptions creationOptions) { this.taskCompletionSource = new TaskCompletionSource <Unit>(creationOptions); }
/// <summary> /// Initializes a new instance of the <see cref="TaskCompletionSource"/> class with the specified options. /// </summary> /// <param name="creationOptions">The options to use when creating the underlying <see cref="Task"/>.</param> public TaskCompletionSource(TaskCreationOptions creationOptions) { _tcs = new TaskCompletionSource<object>(creationOptions); }
public TaskCompletionSource(object state, TaskCreationOptions creationOptions) { this.taskCompletionSource = new TaskCompletionSource <Unit>(state, creationOptions); }
public static TaskCreationOptions AddDenyChildAttach(TaskCreationOptions options) { return options | TaskCreationOptions.DenyChildAttach; }
/// <summary> /// /// </summary> /// <param name="innerQuery"></param> /// <param name="taskScheduler">If null this parameter will be TaskScheduler.Default (evaluated when used in each method, not in ctor)</param> /// <param name="taskCreationOptions">Defaults to DenyChildAttach</param> public AsyncTableQuery(TableQuery <T> innerQuery, TaskScheduler taskScheduler = null, TaskCreationOptions taskCreationOptions = TaskCreationOptions.None) { if (innerQuery == null) { throw new ArgumentNullException("innerQuery"); } _innerQuery = innerQuery; _taskScheduler = taskScheduler; _taskCreationOptions = taskCreationOptions; }
// Utility method for RunTaskFactoryTests(). private static void ExerciseTaskFactoryInt(TaskFactory<int> tf, TaskScheduler tmDefault, TaskCreationOptions tcoDefault, CancellationToken tokenDefault, TaskContinuationOptions continuationDefault) { TaskScheduler myTM = TaskScheduler.Default; TaskCreationOptions myTCO = TaskCreationOptions.LongRunning; TaskScheduler tmObserved = null; Task<int> f; // Helper delegates to make the code shorter. Action init = delegate { tmObserved = null; }; Func<int> int_delegate = delegate { tmObserved = TaskScheduler.Current; return 10; }; Func<object, int> intState_delegate = delegate (object o) { tmObserved = TaskScheduler.Current; return 10; }; //check Factory properties Assert.Equal(tf.CreationOptions, tcoDefault); if (tf.Scheduler != null) { Assert.Equal(tmDefault, tf.Scheduler); } Assert.Equal(tokenDefault, tf.CancellationToken); Assert.Equal(continuationDefault, tf.ContinuationOptions); // // StartNew(func) // init(); f = tf.StartNew(int_delegate); f.Wait(); Assert.Equal(tmObserved, tmDefault); Assert.Equal(f.CreationOptions, tcoDefault); // // StartNew(func, options) // init(); f = tf.StartNew(int_delegate, myTCO); f.Wait(); Assert.Equal(tmObserved, tmDefault); Assert.Equal(f.CreationOptions, myTCO); // // StartNew(func, CT, options, scheduler) // init(); f = tf.StartNew(int_delegate, CancellationToken.None, myTCO, myTM); f.Wait(); Assert.Equal(tmObserved, myTM); Assert.Equal(f.CreationOptions, myTCO); // // StartNew(func<object>, object) // init(); f = tf.StartNew(intState_delegate, 100); f.Wait(); Assert.Equal(tmObserved, tmDefault); Assert.Equal(f.CreationOptions, tcoDefault); // // StartNew(func<object>, object, token) // init(); f = tf.StartNew(intState_delegate, 100, tokenDefault); f.Wait(); Assert.Equal(tmObserved, tmDefault); Assert.Equal(f.CreationOptions, tcoDefault); // // StartNew(func<object>, object, options) // init(); f = tf.StartNew(intState_delegate, 100, myTCO); f.Wait(); Assert.Equal(tmObserved, tmDefault); Assert.Equal(f.CreationOptions, myTCO); // // StartNew(func<object>, object, CT, options, scheduler) // init(); f = tf.StartNew(intState_delegate, 100, CancellationToken.None, myTCO, myTM); f.Wait(); Assert.Equal(tmObserved, myTM); Assert.Equal(f.CreationOptions, myTCO); }
public TaskCompletionSource(TaskCreationOptions creationOptions) : this(null, creationOptions) { }
public TaskCompletionSource(object state, TaskCreationOptions options) { _innerSource = new TaskCompletionSource<object>(state, options); }
public Task <TResult> StartNew(Func <object, TResult> function, object state, TaskCreationOptions creationOptions) { return(StartNew(function, state, cancellationToken, creationOptions, GetScheduler())); }