开发者

Task.Factory.StartNew() Taskscheduler parameter

开发者 https://www.devze.com 2023-01-08 21:45 出处:网络
see: TaskFactory When i want to make a task to be long-running and also to be开发者_运维技巧 cancellable, If i am calling this method from ui,how do i pass the taskscheduler parameter?It\'s not reall

see: TaskFactory

When i want to make a task to be long-running and also to be开发者_运维技巧 cancellable, If i am calling this method from ui, how do i pass the taskscheduler parameter?


It's not really obvious what the problem is. Why can't you just call:

CancellationToken token = new CancellationToken(false);
TaskScheduler scheduler = TaskScheduler.Default;
Task task = taskFactory.StartNew(action, token, 
                                 TaskCreationOptions.LongRunning, scheduler);
0

精彩评论

暂无评论...
验证码 换一张
取 消