You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ikopylov edited this page Dec 26, 2014
·
2 revisions
Qoollo EntryCountingEvent
EntryCountingEvent is a synchronization primitive that allows to track entering clients and wait while they not complete execution.
Sample code:
publicclassSomeManager:IDisposable{privatereadonlyEntryCountingEvent_entryCounter=newEntryCountingEvent();publicvoidFoo(){using(_entryCounter.EnterClientGuarded()){// do some workThread.Sleep(100);}}publicvoidBar(){using(varguard=_entryCounter.TryEnterClientGuarded()){// check if we enter successfullyif(!guard.IsAcquired)return;// do some workThread.Sleep(100);}}publicvoidDispose(){if(!_entryCounter.IsTerminated){// After this call the new clients will not enter Foo and Bar methods_entryCounter.Terminate();// Wait for completion of all already executed clients_entryCounter.Wait();}}}