© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
15 replies
Gopher

Why is my code not thread save?

await Task.WhenAll(tasks).ContinueWith(task => Selection());
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'
System.ArgumentException: 'Destination array was not long enough. Check the destination index, length, and the array's lower bounds. Arg_ParamName_Name'
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Why is my code not runing? [Answered]
C#CC# / help
4y ago
why is my code weird??
C#CC# / help
13mo ago
✅ Why is my code still wrong?
C#CC# / help
3y ago