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 SemaphoreSlim
We can set the value initialCount
& maxCount
by 1 from SemaphoreSlim
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.
private static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1,1);
await semaphoreSlim.WaitAsync();
//your want to avoid race-condition code zone.
semaphoreSlim.Release();