I am attempting to use the TaskFactory Class to create multiple task in parallel, one for each pending transactionId that is being processed, up to a max of 5 threads. I need to pass each task the cancelation token. Am I on the right track? How do i get it to run async vs running sync? I have the following:
public int ProcessPendingTransactions()
{
//set the max # of threads
ThreadPool.SetMaxThreads(5, 5);
//create an action
//The Run method is what i am trying to create multiple tasks in parallel on
Action action = delegate() { abc.Run(transactionId); };
//kick off a new thread async
tfact.StartNew(action, MyCTkn, TaskCreationOptions.None, (TaskScheduler)null);
}