Questions tagged [autoresetevent]

An AutoResetEvent represents a local wait handle event that resets automatically when signaled, after releasing a single waiting thread

An AutoResetEvent represents a local wait handle event that resets automatically when signaled, after releasing a single waiting thread

References

145 questions
578
votes
11 answers

What is the difference between ManualResetEvent and AutoResetEvent in .NET?

I have read the documentation on this and I think I understand. An AutoResetEvent resets when the code passes through event.WaitOne(), but a ManualResetEvent does not. Is this correct?
Ben McNiel
  • 8,661
  • 10
  • 36
  • 38
20
votes
6 answers

AutoResetEvent Reset method

Could someone introduce an use case for AutoResetEvent.Reset() method ? When and why I would like to use this method ? I understand WaitOne and Set but this is quite unclear for me.
anth
  • 1,724
  • 1
  • 19
  • 22
15
votes
3 answers

Whats is the difference between AutoResetEvent and Mutex

I am new to these concepts. But as i am going deeper in threading i am getting confused. What is the significance of mutex, semaphore over autoresetevent. Only difference i came to know with studies is that a mutex can perform across process…
D J
  • 6,908
  • 13
  • 43
  • 75
15
votes
3 answers

new AutoResetEvent (true) Usages in C#?

I was wondering , Why would I ever want to pass a true in the ctor of AutoResetEvent ? I create a waitHandle so that anyone who will call WaitOne() will actually wait. If I instance it with a true , it will be as if it was immediatly signaled -…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
15
votes
6 answers

Java's equivalent to .Net's AutoResetEvent?

What should I use to get semantics equivalent to AutoResetEvent in Java? (See this question for ManualResetEvent).
ripper234
  • 222,824
  • 274
  • 634
  • 905
13
votes
5 answers

AutoResetEvent vs. boolean to stop a thread

I have an object in a worker thread, which I can instruct to stop running. I can implement this using a bool or an AutoResetEvent: boolean: private volatile bool _isRunning; public void Run() { while (_isRunning) { doWork(); …
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
11
votes
7 answers

How to block code flow until an event is fired in C#

I have a grid with a button in a WPF application. When the user clicks the button, a method in a utility class is executed which forces the application to receive a click on the grid. The code flow must stop here and not continue until the user has…
Vahid
  • 5,144
  • 13
  • 70
  • 146
11
votes
5 answers

What does AutoResetEvent.Set() do ?

If I do this : private static System.Threading.AutoResetEvent event_2 = new System.Threading.AutoResetEvent(false); And then in Main thread I do : event_2.Set(); It changes the state from false to true ? If so , it basically does :…
JAN
  • 21,236
  • 66
  • 181
  • 318
10
votes
4 answers

AutoResetEvent Reset immediately after Set

Consider the following pattern: private AutoResetEvent signal = new AutoResetEvent(false); private void Work() { while (true) { Thread.Sleep(5000); signal.Set(); //has a waiting thread definitely been signaled by…
Rotem
  • 21,452
  • 6
  • 62
  • 109
10
votes
1 answer

Synchronizing two threads with AutoResetEvent

I'm trying to implement AutoResetEvent. For the purpose I use a very simple class : public class MyThreadTest { static readonly AutoResetEvent thread1Step = new AutoResetEvent(false); static readonly AutoResetEvent thread2Step = new…
Leron
  • 9,546
  • 35
  • 156
  • 257
10
votes
2 answers

Check AutoResetEvent state

Is it possible to check how actually AutoResetEvent object was treated? Is it fired by timeout or by calling Set() from another method? Here is my code. private AutoResetEvent autoResetEvent = new AutoResetEvent(false); private int timeout =…
Pavel Shchegolevatykh
  • 2,568
  • 5
  • 29
  • 32
8
votes
4 answers

Two threads one core

I'm playing around with a simple console app that creates one thread and I do some inter thread communication between the main and the worker thread. I'm posting objects from the main thread to a concurrent queue and the worker thread is dequeueing…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
7
votes
1 answer

Is there an easy way to implement AutoResetEvent in C++0x?

I understand I've asked this question before: What is the C++ equivalent for AutoResetEvent under Linux? However, I'm learning that in C++0x, the threading library are made much simpler, so I want to pose this question out again, is there an easy…
derekhh
  • 5,272
  • 11
  • 40
  • 60
6
votes
3 answers

AutoResetEvent and multiple Sets

I'm trying to design a data-structure around a stack that blocks until the stack has an item available. I tried using an AutoResetEvent but I think I misunderstood how that synchronization process works. Basically, looking at the following code, I…
sohum
  • 3,207
  • 2
  • 39
  • 63
6
votes
1 answer

How to avoid Safe handle has been closed

I have the following code in a test: private void LoadIncomeStatementViewModel() { using (var evt = new AutoResetEvent(false)) { EventHandler handler = (sender, e) => evt.Set(); …
Jeremy Holt
  • 325
  • 6
  • 16
1
2 3
9 10