Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create named autoresetevent in C#?

I need to synchronize two applications by using a named event. But neither AutoResetEvent nor ManualResetEvent contains constructor with a name for event (only initial state). I can open existing named event through static method OpenExisting in AutoResetEvent or ManualResetEvent class, but can't create It! I don't want to use native WinAPI CreateEvent function for It, unless I know precisely of not existing of other ways.

like image 792
Vasya Avatar asked Sep 29 '11 08:09

Vasya


People also ask

When to use AutoResetEvent c#?

AutoResetEvent is used for send signals between two threads. Both threads share the same AutoResetEvent object. Thread can enter into a wait state by calling WaitOne() method of AutoResetEvent object. When second thread calls the Set() method it unblocks the waiting thread.

What is AutoResetEvent C#?

Calling Set signals AutoResetEvent to release a waiting thread. AutoResetEvent remains signaled until a single waiting thread is released, and then automatically returns to the non-signaled state. If no threads are waiting, the state remains signaled indefinitely.

What is the difference between AutoResetEvent and ManualResetEvent?

An AutoResetEvent resets when the code passes through event. WaitOne() , but a ManualResetEvent does not.

What is ManualResetEvent in C#?

Set to signal that the waiting threads can proceed. All waiting threads are released. Once it has been signaled, ManualResetEvent remains signaled until it is manually reset by calling the Reset() method. That is, calls to WaitOne return immediately.


1 Answers

I found a solution by myself. That is:

EventWaitHandle handle = 
    new EventWaitHandle(false, EventResetMode.ManualReset, "testRemoteServer");
like image 77
Vasya Avatar answered Oct 12 '22 00:10

Vasya