when a C# program holds a named semaphore, it does not seem to be released when the application is terminated early (for example by pressing Ctrl+C or closing the console wi
You can write the mySemaphore.Release(); in class destructor
class Program
{
~Program() // destructor
{
mySemaphore.Release();
}
}
or add a finally pharse to your try\catch
try{}
catch{}
finally
{
mySemaphore.Release();
}
If you are using asp.net you can also use Application_End which located in Global.asax.cs
protected void Application_End(Object sender, EventArgs eventArgs)
{
mySemaphore.Release();
}