C
C#6mo ago
Sammo

System.ArgumentOutOfRangeExpection

Hello, I am getting this error only when running Parallel.ForEach with StringBuilder, other times it does not run this error anyone can help? Thank you My task was to find StringBuilder & Parallel.ForEach speed differents Code Attached below
3 Replies
canton7
canton76mo ago
StringReader isn't thread-safe. It is not safe to append to it from multiple threads at the same time Why are you even trying to use Parallel there? At best, that would meant that your posts would be appended in random order. Or rather, the individual Append calls would be done in a random order, so your HTML would be very broken Note that your string += isn't thread-safe either. It's possible that some of those appends will be dropped
Sammo
Sammo6mo ago
The task was to see different between foreach and Parallel.Foreach I see, we were not told about thread-safe Will come up with another example than, thank you!
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View