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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -