c# - Semaphore timeout after exception -
i have trouble managing resource multiple modules can accessed once @ time securely.
so tried named semaphore this:
var semaphore = new semaphore(1, 1, "_ugly_semaphore_name_"); try { var signaled = semaphore.waitone(120000); // 2 minutes if (!signaled) { return; } // access resource... } { semaphore.release(); } in other module use
var signaled = semaphore.waitone(0); because resource shall accessed if has nothing else do. returns steadly after 6 seconds, 2 minutes should enough believe.
so question is:
if exception occurs in first block of code, afterwards semaphore.waitone() runs timeout. there doing wrong it.
an exception happening during processing not result in other threads waiting on semaphore waiting around timeout. finally block's semantics mean execute if exception causes try block end, releases semaphore.
Comments
Post a Comment