C#C
C#4y ago
Gopher

Why is my code not thread save?

await Task.WhenAll(tasks).ContinueWith(task => Selection());

is in a loop
tasks is a list of tasks which add elements to a list;
Selection is a method which edits the list (cuts off the worse results that were delivered when "tasks" were executed)
I thought that all tasks are finished when starting Selection() and i start it like this afterwards.
But i always get the following error after a few cycles:
System.ArgumentException: 'Destination array was not long enough. Check the destination index, length, and the array's lower bounds. Arg_ParamName_Name'
Was this page helpful?