Questions tagged [manualresetevent]

ManualResetEvent notifies one or more waiting threads that an event has occurred

ManualResetEvent notifies one or more waiting threads that an event has occurred

References

136 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
131
votes
9 answers

How to keep a .NET console app running?

Consider a Console application that starts up some services in a separate thread. All it needs to do is wait for the user to press Ctrl+C to shut it down. Which of the following is the better way to do this? static ManualResetEvent _quitEvent =…
intoOrbit
  • 2,122
  • 2
  • 19
  • 21
23
votes
2 answers

ManualResetEventSlim recommended wait time

The MSDN documentation for ManualResetEventSlim states You can use this class for better performance than ManualResetEvent when wait times are expected to be very short. How long is "very short"? At what point will the benefit of using a kernel…
Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
14
votes
3 answers

Regarding the use of ManualResetEvent usage c#?

i am not familiar with the usage of ManualResetEvent ? is it thread related. what it does and when it is used? here i got a code where ManualResetEvent is used but i just do not understand what it does? here is the code public class Doc :…
Thomas
  • 33,544
  • 126
  • 357
  • 626
14
votes
2 answers

ManualResetEvent vs. Thread.Sleep

I implemented the following background processing thread, where Jobs is a Queue: static void WorkThread() { while (working) { var job; lock (Jobs) { if (Jobs.Count > 0) job =…
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
11
votes
2 answers

Deadlock when locking manualResetEvent

I encounter a deadlock caused when locking instance of manualResetEvent. I can't figure out how to solve it. I will appreciate any help. I have 2 methods in a class performed by different threads: private ManualResetEvent _event = new…
mayap
  • 569
  • 5
  • 19
11
votes
4 answers

Is it safe to signal and immediately close a ManualResetEvent?

I feel like I should know the answer to this, but I'm going to ask anyway just in case I'm making a potentially catastrophic mistake. The following code executes as expected with no errors/exceptions: static void Main(string[] args) { …
Aaronaught
  • 120,909
  • 25
  • 266
  • 342
9
votes
1 answer

Techniques for exiting / cancelling while loops across threads: bool, ManualResetEvent or CancellationToken

I am writing a program that has a few threads, each with a while loop that runs until the user specifies it should stop. I thought of a few ways to exit out of the loops, and subsequently the threads, and have outlined these approaches…
9
votes
7 answers

To make a choice between ManualResetEvent or Thread.Sleep()

I am not sure which strategy to adopt...I am focusing on my operation getting completed, but I'd also like to keep performance issues to a min too...there is a method called Execute() which has to wait (run synchronously) until an operation…
deostroll
  • 11,661
  • 21
  • 90
  • 161
6
votes
4 answers

Lightweight alternative to Manual/AutoResetEvent in C#

I have written what I hope is a lightweight alternative to using the ManualResetEvent and AutoResetEvent classes in C#/.NET. The reasoning behind this was to have Event like functionality without the weight of using a kernel locking object. Although…
sweetlilmre
  • 682
  • 6
  • 13
6
votes
2 answers

ManualResetEvent WaitOne blocks the owner Thread of my CollectionView

I've written a WPF WizardFramework which performs some actions in the background using some BackgroundWorker. While processing it can happen that I have to update an ObservableCollection which is bound to my UI. For this case I've written a…
Herm
  • 2,956
  • 19
  • 32
6
votes
2 answers

ManualResetEvent.WaitOne() doesn't return if Reset() is called immediately after Set()

I have a problem in a production service which contains a "watchdog" timer used to check whether the main processing job has become frozen (this is related to a COM interop problem which unfortunately can't be reproduced in test). Here's how it…
Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
6
votes
2 answers

WinForms RichTextBox : how to reformat asynchronously, without firing TextChanged event

This is a followup to WinForms RichTextBox: how to perform a formatting on TextChanged? I have a Winforms app with a RichTextBox, the app auto-highlights the content of said box. Because the formatting can take a long time for a large document, 10…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
6
votes
2 answers

Asynchronous Client Socket ManualResetEvent holding up execution

I am attempting to utilize MSDN's Asynchronous Client Socket code sample to connect and control some home equipment. As I understand, the sample code's ReceiveCallback method uses an instance of the EventWaitHandle ManualResetEvent and the method…
Bill
  • 335
  • 1
  • 4
  • 21
5
votes
1 answer

Can Task.Delay cause thread switching?

I have a long running process that sends data to the other machine. But this data is received in chunks (like a set of 100 packets, then delay of minimum 10 seconds). I started the sending function on a separate thread using Task.Run(() => {…
1
2 3
9 10