Task.Factory.StartNew() Taskscheduler parameter
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);
精彩评论