Sychronization of threads via events

D

Dan

The Win32 API lets you create named events via CreateEvent. However, the
..NET equivalents, AutoResetEvent and ManualResetEvent, don't appear to let
you do that. Is there a way to create the equivalent of a named event in
..NET?

Thanks...

Dan
 
S

Scott Allen

Hi Dan:

There is no way to create a named event with the framework classes.
You'll have to PInvoke CreateEvent.
 
N

Nicholas Paldino [.NET/C# MVP]

Dan,

In 1.1, you can call CreateEvent through the P/Invoke layer, and get the
handle to the event. Once you have it, you should be able to pass the
result to the Handle property of an AutoResetEvent or a ManualResetEvent
(whichever one is appropriate).

In .NET 2.0, you can use the EventWaitHandle class and pass a name
through the constructor. The inheritance chains for ManualResetEvent and
AutoResetEvent have been changed to derive from this (which in turn, derives
from WaitHandle).

Hope this helps.
 
R

Richard Blewett [DevelopMentor]

I wrote a named event wrapper which you can get from here (the project also has a thread which expses a WaitHandle so you can wait on multiple threads too).

http://staff.develop.com/richardb/dotnet/dm.threading.zip

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

The Win32 API lets you create named events via CreateEvent. However, the
.NET equivalents, AutoResetEvent and ManualResetEvent, don't appear to let
you do that. Is there a way to create the equivalent of a named event in
.NET?

Thanks...

Dan



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004



[microsoft.public.dotnet.languages.csharp]
 
D

Dan

Thanks Richard.

Richard Blewett said:
I wrote a named event wrapper which you can get from here (the project
also has a thread which expses a WaitHandle so you can wait on multiple
threads too).
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/ said:
The Win32 API lets you create named events via CreateEvent. However, the
.NET equivalents, AutoResetEvent and ManualResetEvent, don't appear to let
you do that. Is there a way to create the equivalent of a named event in
.NET?

Thanks...

Dan



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004



[microsoft.public.dotnet.languages.csharp]
 

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