It seems like I am getting threading errors as a result of an inconsistent state of my IEnumerable
. Specifically, List<T>
.
Here's my workflow:
List<string> IDs = getIDs();
RunTask(IDs);
RunTask(IDs);
public void RunTask(List<string> IDs)
{
TaskScheduler scheduler = new TaskScheduler();
TaskFactory factory = new TaskFactory(scheduler);
var tasks = IDs.Select(name => factory.StartNew(() => action(name))).ToArray();
Task.WaitAll(tasks);
}
I am getting a generic error on my WaitAll()
call.
My thinking is that I am getting some sort of unsynchronized IEnumerator, and that I need to make a copy of my List
via Array.CopyTo()
, then pass it into my multiple threads.
This is my exception:
Error: One or more errors occurred.
One or more errors occurred.
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
Any thoughts on this matter?