In .NET, is there a way to get the count on a semaphore. I don’t need a threadsafe count, just a reasonable approximation so report the status on a GUI thread.
Currently I’m using a dual-counter. The real semaphore and another variable that is incremented and decremented in sync, but this is annoying and error prone.
No. To do this you would have to wrap (subclass) Semaphore into something with a counter. Since you don’t care about thread safety it won’t be that hard.