Questions tagged [waithandle]

In .Net, WaitHandles are used for synchronization among threads. They contain a handle to the OS's synchronization primitive. Mutex, Semaphore, and EventWaitHandle are exemples of classes that inherit from WaitHandle.

See http://www.albahari.com/threading/part2.aspx for a tour of the available synchronization constructs in .Net.

113 questions
6
votes
6 answers

When should I use a WaitHandle instead of a lock

In C#, when we should use WaitHandle instead of lock ?
Xaqron
  • 29,931
  • 42
  • 140
  • 205
6
votes
1 answer

How-to dispose a waithandle correctly

I'm doing some multi-threading and use AutoResetEvents and ManualResetEvents do control my main - loop. When "destryoing" the threads I also have to dispose these signals, that's clear. But I saw different ways how to dispose Waithandles, and I'm…
TomTom
  • 992
  • 2
  • 10
  • 26
6
votes
3 answers

How to wait for the first of the 2: a process and an EventWaitHandle

I want to WaitForMultipleObjects on 2 different types: an 'EventWaitHandle' a 'Process.Handle' ==> intptr I don't know how to convert (in the appropriate way) "process.Handle" to a WaitHandle in order to have the following code working: var…
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
6
votes
1 answer

C# WaitHandle cancelable WaitAll

I have the following code which has the goal to wait for all given wait handles but is cancellable by a specific wait handle: public static bool CancelableWaitAll(WaitHandle[] waitHandles, WaitHandle cancelWaitHandle) { var waitHandleList = new…
Harry13
  • 733
  • 1
  • 4
  • 15
6
votes
2 answers

WaitHandle.WaitAny and Semaphore class

Edit: I'd like to plead temporary insanity for even asking this question, but it made sense at the time (see edit 2 below). For a .NET 3.5 project, I have two types of resources (R1 and R2) that I need to check the availability of. Each resource…
Thorarin
  • 47,289
  • 11
  • 75
  • 111
5
votes
3 answers

How to make a nonblocking wait handle?

Essentially, what I'm doing is creating a web server to handle an API call, and then when it's done continue the method execution, so essentially: new WebServer(myAutoResetEvent); myAutoResetEvent.WaitOne(); However, this blocks the thread until…
It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
5
votes
1 answer

Using WaitHandle.WaitOne

I am attempting to create a windows service that polls every 5 minutes a system and checks for some action that needs done. I have read up on WaitHandles and their usefulness in this area, but need to understand how this works. See code…
steventnorris
  • 5,656
  • 23
  • 93
  • 174
5
votes
1 answer

Why doesn't my NamedPipeServerStream wait?

I'm working with a NamedPipeServerStream to communicate between two processes. Here is the code where I initialize and connect the pipe: void Foo(IHasData objectProvider) { Stream stream = objectProvider.GetData(); if (stream.Length > 0) …
Farnk
  • 244
  • 3
  • 12
4
votes
1 answer

Combining Wait Handles?

Bit of an interesting one here I think. I have a class thats in charge of "multiplexing" a number of processing operations onto a fixed number of threads. The typical case is a sort of producer/consumer problem, where each operation consists of a…
LorenVS
  • 12,597
  • 10
  • 47
  • 54
4
votes
3 answers

Make asynchronous call synchronize

I trying to synchronize a asynchronous call. The regular (async) flow look like: Asking the server for data using telnet: 'Session.sendToTarget(message)' The app move on doing other things.... When the server answer ready, the server send the…
Alon Ashkenazi
  • 1,223
  • 4
  • 21
  • 29
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
4
votes
4 answers

Logic to kill a process within a time limit

I want to ensure that my logic is correct here. I want to run a process for timeout seconds, if it runs for longer it should be immediately killed. The completed flag should reliably indicate whether the process completed as intended, e.g was not…
Sean Thoman
  • 7,429
  • 6
  • 56
  • 103
4
votes
6 answers

For a windows service, which is better, a wait-spin or a timer?

This question about Timers for windows services got me thinking: Say I have (and I do) a windows service thats waiting on a WaitHandle and when woken, it dives into a wait-spin like I have shown below in a flowchart wait spin diagram…
Allen Rice
  • 19,068
  • 14
  • 83
  • 115
4
votes
1 answer

Best approach to Timeout using HttpWebRequest.BeginGetResponse

HttpWebRequest.BeginGetResponse doesn´t respect any Timeout properties from HttpWebRequest(Timeout or ReadWriteTimeout). I read some approaches to get the same results, but I don't know if it's the best way to do it and if I should use for few calls…
Felipe Pessoto
  • 6,855
  • 10
  • 42
  • 73
3
votes
4 answers

Run Message Loop while waiting for WaitHandle

Is there any way to process all Windows messages while the UI thread is waiting on a WaitHandle or other threading primitive? I realize that it could create very messy reentrancy problems; I want to do it anyway. EDIT: The wait occurs in the middle…
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964