Suppresses the flow of ExecutionContext until it is disposed.
Note that this is a ref-struct to avoid it being used in an async method.
Exemplo n.º 1
0
        public static void QueueThreadPoolWorkItem(this TaskScheduler taskScheduler, IThreadPoolWorkItem workItem)
        {
            using var suppressExecutionContext = new ExecutionContextSuppressor();

            var workItemTask = new Task(ThreadPoolWorkItemTaskFunc, workItem);

            workItemTask.Start(taskScheduler);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public static void QueueWorkItem(this TaskScheduler taskScheduler, IWorkItem todo)
        {
            using var suppressExecutionContext = new ExecutionContextSuppressor();

            var workItemTask = new Task(TaskFunc, todo);

            workItemTask.Start(taskScheduler);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        /// <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);
            }
        }