public static void QueueThreadPoolWorkItem(this TaskScheduler taskScheduler, IThreadPoolWorkItem workItem) { using var suppressExecutionContext = new ExecutionContextSuppressor(); var workItemTask = new Task(ThreadPoolWorkItemTaskFunc, workItem); workItemTask.Start(taskScheduler); }
public static void QueueAction(this TaskScheduler taskScheduler, Action <object> action, object state) { using var suppressExecutionContext = new ExecutionContextSuppressor(); var task = new Task(action, state); task.Start(taskScheduler); }
public static void QueueWorkItem(this TaskScheduler taskScheduler, IWorkItem todo) { using var suppressExecutionContext = new ExecutionContextSuppressor(); var workItemTask = new Task(TaskFunc, todo); workItemTask.Start(taskScheduler); }
public static Timer Create(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } // Don't capture the current ExecutionContext and its AsyncLocals onto the timer using var suppressExecutionContext = new ExecutionContextSuppressor(); return(new Timer(callback, state, dueTime, period)); }
/// <summary> /// Start the monitor. /// </summary> public void Start() { using var suppressExecutionContext = new ExecutionContextSuppressor(); lock (_lockObj) { if (_stoppingCancellation.IsCancellationRequested) { throw new InvalidOperationException("This instance has already been stopped and cannot be started again"); } if (_runTask is not null) { throw new InvalidOperationException("This instance has already been started"); } _runTask = Task.Run(Run); } }