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
5
votes
4 answers

Should I use ManualResetEvent as a lock object?

The method below should return true for the first call, and false for any other call. Is there any problem with it? Is it safe to use the reset event for locking? private ManualResetEvent _resetEvent = new ManualResetEvent(false); public bool…
HuBeZa
  • 4,715
  • 3
  • 36
  • 58
5
votes
1 answer

ManualResetEventSlim.Set() does not always unlock the Wait inside a Task

I am trying to use the ManualResetEventSlim class to communicate between a few parallel Tasks. Here is a simplified version of the code: class Program { private static void Main(string[] args) { Stopwatch stopwatch =…
Rojan Gh.
  • 1,062
  • 1
  • 9
  • 32
5
votes
1 answer

EventHandle.WaitOne + WebBrowser = Deadlock when waiting for DocumentComplete

I've got a Problem with the automatisation of WebBrowsing in an C#-Program. I've used the code before for a BHO and there it was working. But within a pure c# Program there seems to be some kind of deadlock. I've instructed my program to click on a…
lichtbringer
  • 125
  • 1
  • 1
  • 10
5
votes
1 answer

When should a ManualResetEvent be disposed?

I'm using an application that synchronizes threads using ManualResetEvent. FxCop told me to dispose those objects. I found the following discussion which told me the same: Do I need to Dispose() or Close() an EventWaitHandle? But I don't know when…
Sebastian Schumann
  • 3,204
  • 19
  • 37
5
votes
2 answers

How do I tell whether a Windows kernel Event object is auto-reset or manual-reset?

Windows allows the creation of (named) Event objects. An Event (the synchronization primitive in Windows) can be of type auto-reset (in which case you could say it's kind of a semaphore) or it can be of type manual-reset in which case it remains set…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
5
votes
4 answers

ManualResetEvent WaitOne not unblocking

I'm a little confused over a ManualResetEvent that I'm using which doesn't appear to be unblocking. Anyone know why this might be the case? The scenario I've got is something along these lines. The real situation is quite complicated and I've not…
Ian
  • 33,605
  • 26
  • 118
  • 198
4
votes
1 answer

Lazy initialization of a singleton with parameters

I am trying to create a singleton which has a non-empty constructor and to access it into a synchronized way: since I have no control on the order of initialization of my component, if a component access the singleton before it's initialized, it has…
Edmondo
  • 19,559
  • 13
  • 62
  • 115
4
votes
2 answers

Will the ManualResetEvent consume cpu while it is in a wait state?

More specifically, does the performance degradation of context switching apply to threads that are in a wait state? Under what conditions or circumstances would a ManualResetEvent, or WaitHandle, be likely to consume resources?
Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
4
votes
0 answers

.net Core console app - exit signal has a hard stop time

I have a number of console apps that need to be built that all run "Jobs". They will be long running processes - never ended, and they continually do work. With that in mind, I'm hoping to build a generic way to host these jobs. Each will be a…
Rob
  • 6,819
  • 17
  • 71
  • 131
4
votes
1 answer

What resources do AutoResetEvent / ManualResetEvent consume?

Are the c# ManualResetEvent and AutoResetEvent classes expensive to create or to maintain? Do they consume some kind of limited Windows kernel resources, and if so, how limited is it? E.g. if I have code that can create a new AutoResetEvent every…
HugoRune
  • 13,157
  • 7
  • 69
  • 144
3
votes
4 answers

ManualResetEvent.WaitOne blocks all threads

i have following code ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadAsync), apiMethod); downloadHandle.WaitOne(); Where DownloadAsync is private void DownloadAsync(object _uri) { var url = _uri as string; …
3
votes
1 answer

Is ManualResetEventSlim with spinCount = 0 the same as ManualResetEvent?

As far as I know, slim versions of synchronization primitives use spin waits before using resources of the kernel. Is it true that ManualResetEventSlim with spinCount = 0 is the same as the usual ManualResetEvent? new…
Palindromer
  • 854
  • 1
  • 10
  • 29
3
votes
1 answer

What is the minimum wait time to use ManualResetEventSlim instead of ManualResetEvent?

From NET 4 I can use the ManualResetEventSlim class that make a little spinning before blocking in order to get a time optimization if the blocking time is little (I have no context switch). I'd like to measure using a benchmark how little is this…
Rowandish
  • 2,655
  • 3
  • 31
  • 52
3
votes
1 answer

Why do multiple waits on cascaded ManualResetEvents triple the execution time?

I have simplified the scenario as that I have as good as possible. Down below you find the complete code with which you can test the program yourself. In my use case I have to wait for a reset event from another Thread - lets call that subEvent. The…
Yggdrasil
  • 1,377
  • 2
  • 13
  • 27
3
votes
1 answer

Is Wait()-ing on a ManualResetEventSlim guaranteed to throw on cancellation?

Given the following code: CancellationTokenSource cts = new CancellationTokenSource(); ManualResetEventSlim mre = new ManualResetEventSlim(); and these two threads executing concurrently: mre.Wait(cts.Token); cts.Cancel(); mre.Set(); is the…
BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
1
2
3
9 10