Task scheduler what is it




















Tasks can be scheduled to execute in response to these events, or triggers. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services.

Privacy policy. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Please enable JavaScript on your browser to best view this site. Microsoft Windows includes a Task Scheduler utility that allows you to run programs automatically at a specific time and at a set interval.

This is useful for scheduling important administration tasks such as Windows Backup. Use the buttons below to navigate through the lesson. Select the Application from the list, if the application is not on the list then click on Browse. The TaskScheduler class also serves as the extension point for all customizable scheduling logic. This includes mechanisms such as how to schedule a task for execution, and how scheduled tasks should be exposed to debuggers.

If you require special functionality, you can create a custom scheduler and enable it for specific tasks or queries. In this topic: The default task scheduler and the thread pool The global queue vs.

The thread pool uses the information that is provided by the Task type to efficiently support the fine-grained parallelism short-lived units of work that parallel tasks and queries often represent.

The thread pool maintains a global FIFO first-in, first-out work queue for threads in each application domain. Whenever a program calls the ThreadPool. UnsafeQueueUserWorkItem method, the work is put on this shared queue and eventually de-queued onto the next thread that becomes available. Starting with the. By using this lock-free implementation, the thread pool spends less time when it queues and de-queues work items. This performance benefit is available to all programs that use the thread pool.

Top-level tasks, which are tasks that are not created in the context of another task, are put on the global queue just like any other work item. However, nested or child tasks, which are created in the context of another task, are handled quite differently. A child or nested task is put on a local queue that is specific to the thread on which the parent task is executing.

The parent task may be a top-level task or it also may be the child of another task. When this thread is ready for more work, it first looks in the local queue. If work items are waiting there, they can be accessed quickly. The local queues are accessed in last-in, first-out order LIFO to preserve cache locality and reduce contention.

For more information about child tasks and nested tasks, see Attached and Detached Child Tasks. The use of local queues not only reduces pressure on the global queue, but also takes advantage of data locality. Work items in the local queue frequently reference data structures that are physically near one another in memory.

In these cases, the data is already in the cache after the first task has run and can be accessed quickly. NET Framework 4, the thread pool also features a work-stealing algorithm to help make sure that no threads are sitting idle while others still have work in their queues.

When a thread-pool thread is ready for more work, it first looks at the head of its local queue, then in the global queue, and then in the local queues of other threads. If it finds a work item in the local queue of another thread, it first applies heuristics to make sure that it can run the work efficiently. If it can, it de-queues the work item from the tail in FIFO order. This reduces contention on each local queue and preserves data locality.

This architecture helps the thread pool load-balance work more efficiently than past versions did. You may want to explicitly prevent a task from being put on a local queue. For example, you may know that a particular work item will run for a relatively long time and is likely to block all other work items on the local queue.

In this case, you can specify the System. TaskCreationOptions option, which provides a hint to the scheduler that an additional thread might be required for the task so that it does not block the forward progress of other threads or work items on the local queue.

By using this option you avoid the thread pool completely, including the global and local queues. In some cases when a Task is waited on, it may be executed synchronously on the thread that is performing the wait operation. This enhances performance by preventing the need for an additional thread and instead using the existing thread, which would have blocked otherwise. To prevent errors due to reentrancy, task inlining only occurs when the wait target is found in the relevant thread's local queue.



0コメント

  • 1000 / 1000