I have
try
{
using (var eventWaitHandle = EventWaitHandle.OpenExisting(name))
{
eventWaitHandle.Set();
}
Environment.Exit(0);
}
catch(WaitHandleCannotBeOpenedException)
{
// register new handle code goes here
}
Is there any way to do that without throwing/handling exceptions?
Since
.NET 4.5you can eliminateWaitHandleCannotBeOpenedExceptionexception for case when named system event does not exist by usingTryOpenExisting()method:MSDN: