What is the best way to reset a semaphore that has threads waiting on it. Right now all I can think of is just a while loop and freeing up the semaphore until the semaphore is completely eliminated. I'm not sure what is the best.
semaphore.Close(); semaphore = new Semaphore(0,1);
or
while(true) { try { semaphore.Release(); } catch { break; } } semaphore = new Semaphore(0,1);
If you want to do this, are you sure you want to start with Semaphore? Perhaps it might be more appropriate ManualResetEvent?
Semaphore
ManualResetEvent
, , , . , . , , catch catch (SemaphoreFullException).
catch
catch (SemaphoreFullException)
, , . - , , WaitOne , , , Release, SemaphoreFullException.
WaitOne
Release
SemaphoreFullException
"" - , : . , , , , .,.
Source: https://habr.com/ru/post/1770763/More articles:How to add & ref = 123 to each link - javascriptCompiling F # code on Mono 2.8 - compilationdelegates and events - c #Generating an ASP.NET session timeout in a GeneXus application - loginBe careful with version numbers for downloading signed assemblies - reflectionProblems with gallery layouts - androidHow do I popViewControllerAnimated after a delay? - iosHow can I write this jQuery snippet more beautiful - jqueryCreating a Django admin action to duplicate a record - djangoms-access: when I change the extension to ACCDR, forms / tables disappear - vbaAll Articles