Reputation: 8708
I created a TaskScheduler and i am passing it as an argument across two different tasks.
Is there any problem in doing it? Should i be creating a new TaskScheduler instance for each task?
Here's the sample example (actual code inside each task removed for sake of simplicity)
var uiSch = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
var t1 = Task.Factory.StartNew<List<Carrier>>(() =>
{
//does stuff
})
.ContinueWith(previous =>
{
//does stuff
},
System.Threading.CancellationToken.None,
TaskContinuationOptions.OnlyOnRanToCompletion,
uiSch);
var t2 = Task.Factory.StartNew<List<Logic.WarehouseLogic.Warehouse>>(() =>
{
//does stuff
})
.ContinueWith(previous =>
{
//does stuff
},
System.Threading.CancellationToken.None,
TaskContinuationOptions.OnlyOnRanToCompletion,
uiSch);
[EDIT1]
My question was partially related to the following error: 'The current SynchronizationContext may not be used as a TaskScheduler' A fix can be found here
Upvotes: 0
Views: 186
Reputation: 217313
There is no problem scheduling multiple tasks on the same task scheduler.
Upvotes: 5