[英]Regarding usage of TaskScheduler.FromCurrentSynchronizationContext & Task.Factory.StartNew()
i am new in MS TPL. 我是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. 所以我看到有些时候人们在使用Task.Factory.StartNew()
启动任何任务时使用TaskScheduler.FromCurrentSynchronizationContext
,并且有些时候人们启动任务时不使用TaskScheduler
。
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() =>
{
});
Task.Factory.StartNew(() =>
{
});
so please someone tell me what is the use of TaskScheduler
? 所以请有人告诉我TaskScheduler
什么用? when TaskScheduler
should use along with Task.Factory.StartNew
and when should not use TaskScheduler
. 当TaskScheduler
应该与Task.Factory.StartNew
一起使用时,不应该使用TaskScheduler
。
please explain with small sample code for better understand the usage of TaskScheduler
. 请用小样本代码解释,以便更好地理解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
. 如果您希望给定任务在UI线程上运行,则使用uiScheduler
作为给定的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
. 如果您希望任务在线程池线程中运行,这是默认行为,请不要提供任何TaskScheduler
,也不要提供TaskScheduler.Default
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.