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
3
votes
0 answers

System.Threading.Timer's Dispose method does not work with ManualResetEventSlim?

I have the following code for a sample console app to simulate a Windows Service. class Program { private Timer timer; private object syncRoot = new object(); private bool stopSignalled = false; private ManualResetEventSlim mre = new…
Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93
3
votes
1 answer

multithreading's performance is related to global queue's length if queue is not locked?

The requirement is: Items to deal with are stored in a global queue. Several handler threads get item from global queue to handle. Producer thread adds item to global queue continuously and rapidly(much faster than all dealer threads' processing…
3
votes
2 answers

ManualResetEvent.WaitOne() throws NullReferenceException: Object reference not set to an instance of an object

I have a weird random NPE error when dealing with ManualResetEvent.WaitOne(). Here's my code. I have a method that creates ManualResetEvent object and then it passes it down to the Windows Workflow Foundation (WWF) workflow instance as one of the…
JKK
  • 311
  • 1
  • 4
  • 15
3
votes
3 answers

ManualResetEvent is not waiting for threadpool completion

I have list of batches to process. forever. I want to do each chunk (5) in parallel, and when it is done move to the next chunk. for some reason, the code bellow is not waiting for the chunk to be done and continue even if it is not completed. …
SexyMF
  • 10,657
  • 33
  • 102
  • 206
3
votes
1 answer

Dispose WaitOne function stuck timer callback

I have a timer that it's callback do somethings: The timer: dataProcessingTimer = new System.Threading.Timer(new TimerCallback(DataProcessingTimerHandler), null, 0, _dataProcessingTimerPollingInterval); The callback: void…
Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111
3
votes
1 answer

Conditional event waiting / ManualResetEvent

I know how to use the ManualResetEvent or synchronization primitives (like Monitor) to wait for events and/or locks, but I am wondering if there is a way to implement something like the following: ManualResetEvent resetEvent; public string…
Sean Thoman
  • 7,429
  • 6
  • 56
  • 103
3
votes
1 answer

Issue with ManualResetEvent not releasing all waiting threads consistently

I'm trying to implement a class which uses a simple cache for holding data retrieved from an internal service. I'm using a ManualResetEvent to block multiple threads which may try to refresh the cached data at the same time with the first thread to…
gouldos
  • 1,015
  • 1
  • 16
  • 30
2
votes
3 answers

Is it safe to catch ObjectDisposedException on ManualResetEvent.WaitOne()?

This is closely related to Is it safe to signal and immediately close a ManualResetEvent? and might provide one solution to that problem. Say I have a bunch of threads that potentially want to do the same work, but only one should be allowed to do…
Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156
2
votes
1 answer

C# ManualResetEvent Reset vs WaitOne

https://learn.microsoft.com/en-us/dotnet/api/system.threading.manualresetevent?view=net-6.0 I am having a hard time understanding the difference between Reset() and WaitOne(). What is the difference in these two if they are both blocking the thread.
John
  • 47
  • 2
2
votes
1 answer

Error while setting ManualResetEvent on callback mock setup

I am making use of ManualResetEvent class in a test. Basically, I want to invoke the Set() method when a particular function is called. This looks like: var mre = new ManualResetEvent(false); mockObj.Setup(dmc => dmc.Foo(param1, param2,…
learntogrow-growtolearn
  • 1,190
  • 5
  • 13
  • 37
2
votes
1 answer

Why does ManualResetEventSlim.Wait appear not to block for the full wait time?

So I am using System.Threading.ManualResetEventSlim in my code and I happened to notice that sometimes when I call Wait(TimeSpan) the time spent waiting is significantly less than the time specified. Here is a unit test that demonstrates my…
Chris Fewtrell
  • 7,555
  • 8
  • 45
  • 63
2
votes
0 answers

Xamarin.Forms : EventHandler can not fire when using ManualResetEvent.WaitOne only in iOS (works fine in Android)

I'm working on a single App with Xamarin.Forms, Visual Studio. I'm using a ManualResetEvent in my code to wait for an event to fire. No problem with Android, but in iOs, myManualResetEvent.WaitOne(5000) is waiting infinitely. But, as soon as I get…
2
votes
4 answers

How to use ManualResetEvent without freezing my UI

I want to use ManualResetEvent instead of Thread.Sleep to prevent my UI from freeing. This is what I have tried: private ManualResetEvent manualResetEvent = null; private void Form1_Load(object sender, EventArgs e) { ManualResetEvent…
user3328870
  • 341
  • 2
  • 7
  • 23
2
votes
2 answers

setEvent is called without ResetEvent

what happens if a manual-reset event is set using setEvent but not reset using ResetEvent; and that event is triggered multiple times.i.e. while the event is getting processed, again the event is set. following is the sample task: void foo() { ... …
2
votes
1 answer

Effect of creating large amounts of system threads and waiting on MRE?

I'm trying to fix memory spikes in a very large application. While I'm not sure how much of an effect this would have on memory, I noticed the following: Application uses a custom thread pool to do all expensive tasks Application will execute all…
John Humphreys
  • 37,047
  • 37
  • 155
  • 255
1 2
3
9 10