i am new in MS TPL. so i have seen some time people use TaskScheduler.FromCurrentSynchronizationContext
when start any task using Task.Factory.StartNew()
and some time TaskScheduler
is not use when people start task.
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() =>
{
});
Task.Factory.StartNew(() =>
{
});
so please someone tell me what is the use of TaskScheduler
? when TaskScheduler
should use along with Task.Factory.StartNew
and when should not use TaskScheduler
.
please explain with small sample code for better understand the usage of TaskScheduler
.
another question how can we schedule a task like that when we create task how can i specify time or date or day when task need to start. thanks
If you want the given task to run on the UI thread then use the uiScheduler
as the given TaskScheduler
. If you want the task to run in a thread pool thread, which is the default behavior, don't provide any TaskScheduler
, or provide TaskScheduler.Default
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.