I am running to the below issue and unable to workaround it
https://andrew.thomas.net.nz/c%23/2020/08/30/Beware-of-using-File-Stream-WriteLineAsync-methods/
I am unable to workaround it since await can't be included inside lock and do not want to use async-lock implementations so looking for your thoughts to help me fixing this issue with a simple solution.
Short Answer, If you don't want to use any signal or lock that might be impossible to avoid the problem.
To avoid that thing you need to control your thread access resource, otherwise, you might encounter the race-condition problem.
if you don't want to use
lock
there is another way to control thread access resource at the same time SemaphoreSlimWe can set the value
initialCount
&maxCount
by 1 fromSemaphoreSlim
which represents that only one thread can use the resource others will wait for the signal at the same time when you are using multiple threads.