c# - How to check whether a SemaphoreSlim can be entered? -
i want assign list of objects in semaphoreslim fashion, e.g. suppose each object can used 2 threads @ same time. plan create semaphoreslim class each object in list, question how should check whether semaphoreslim can used right now?
i don't want call wait() since if object not available can move on next 1 in list. don't want check currentcount property either since don't think thread safe if multiple threads checked currentcount @ same time , decided call wait() if currentcount larger zero.
so ideal solution scenario?
btw - can use other solutions - not semaphoreslim.
i suspect can use wait(timespan.zero)
"try acquire semaphore, abandon attempt if can't immediately."
that expectation, documentation doesn't explicitly talk happens if pass in timespan.zero
. it's worth @ least investigating option further, imo.
Comments
Post a Comment