EventWaitHandle.OpenExisting oddity

D

Dilip

I have an application (lets call it app_1) that creates a named event
using the EventWaitHandle class and friends. I use it to determine
from other external apps if app_1 is still running. I do it by
performing an EventWaitHandle.OpenExisting on the said named event.

The problem is even after app_1 is shut down (the named event is
properly closed before app_1 exits) doing EventWaitHandle.OpenExisting
from other external applications still succeeds! This is a problem
for me because now I can no longer rely on the absence of the event to
tell me if app_1 is running or not.

Why is the event still hanging around? I know there are other ways to
detect if a process is running or not but I want to know why this
won't work.
 
P

Peter Duniho

[...]
Why is the event still hanging around? I know there are other ways to
detect if a process is running or not but I want to know why this
won't work.

I don't know the answer to your question. It's unlikely (but not
impossible) that most anyone else would know either, without seeing a
concise-but-complete code sample that reliably demonstrates the problem.
A few people might have the answer off the top of their head, based on
their prior knowledge of how named events work. But you haven't given
anyone much to go on.

That said, the more usual way to deal with this is to use a named Mutex.
That should work fine and is IMHO the way to go.

Pete
 
D

Dilip

[...]
Why is the event still hanging around? I know there are other ways to
detect if a process is running or not but I want to know why this
won't work.

I don't know the answer to your question. It's unlikely (but not
impossible) that most anyone else would know either, without seeing a
concise-but-complete code sample that reliably demonstrates the problem.
A few people might have the answer off the top of their head, based on
their prior knowledge of how named events work. But you haven't given
anyone much to go on.

Peter
Thanks for responding. I figured out the problem. While doing
OpenExisting from other applications, I didn't wrap the calls around
using block. Consequently it left the handles open, so I couldn't
reliably detect whether app_1 was running or not. In my defense, I
never used the return values of the OpenExisting calls, so I for some
reason mistakenly thought the handle count wouldn't be bumped. I
thought:

EventWaitHandle ewh = EventWaitHandle.OpenExisting(........);

only will increment the handle count of the event.

Obviously I was wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top