I have a piece of code in an Async / Await function, and I want one thread to execute at a time.
This is relatively simple by creating a new SemaphoreSlim (1) and using WaitAsync / Release. The effect is that the first thread executes and the rest wait and then execute one after another.
What I'm trying to achieve is actually a little different. I would like other threads not to expect, but to return from a function (i.e. I don't want to block other threads). Therefore, if the "NumberOfThreadsCurrentlyExecuting" property existed, I would effectively have If Semaphore.NumberOfThreadsCurrentlyExecuting> 0 Then Return.
But such a property does not exist. Does anyone know how to solve this problem?
Thanks Charles
source
share