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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

jquery - ReferenceError: CKEDITOR is not defined -

android - Go back to previous fragment -