The docs for the createdNew return from the EventWaitHandle constructor are
wrong and there's a bug in the createdNew out parameter, but I was able to
use this constructor to do what you're trying to do with two applications.
Always use the constructor that creates the event, regardless of which
application is calling. That way, you simply don't care who created the
event; either application can win that race and it doesn't matter to either
one.
My test has an edit field for the event name and four buttons (create/open,
wait, set, and reset). I'm also using an auto-reset event, rather than
manual, but it shouldn't make any difference. Here's my basic code (same
for both programs):
-----
private void OpenCreateButton_Click(object sender, System.EventArgs e)
{
// Open the event.
bool createdNew;
ewh = new EventWaitHandle( false, EventResetMode.AutoReset,
EventNameEdit.Text, out createdNew );
if ( createdNew )
{
System.Diagnostics.Debug.WriteLine( "The event was created, not just
opened." );
}
else
{
System.Diagnostics.Debug.WriteLine( "The event was opened, not
created." );
}
}
private void WaitButton_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine( "Waiting for the event..." );
if ( ewh.WaitOne( 10000, false ) )
{
System.Diagnostics.Debug.WriteLine( "Wait successful." );
}
else
{
System.Diagnostics.Debug.WriteLine( "Wait timed-out." );
}
}
private void SetButton_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine( "Setting event..." );
ewh.Set();
System.Diagnostics.Debug.WriteLine( "Set done." );
}
private void ResetButton_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine( "Resetting event..." );
ewh.Reset();
System.Diagnostics.Debug.WriteLine( "Reset done." );
}
-----
I can connect to the event from either program first, neither cares. I can
wait for the event in either program and set it from the other program and
everything works exactly as expected. Note that I've modified my version of
the EventWaitHandle source code for OpenNETCF to fix the createdNew bug,
but, other than that, it's the code found in SDF 1.4 that I'm using.
Paul T.