Questions tagged [event-wait-handle]

51 questions
0
votes
0 answers

How to safely dispose of a WaitHandle?

Consider this code: volatile EventWaitHandle waitHandle; // Thread1, represents an IO-bound worker thread: while (true) { waitHandle?.Set(); } // Thread 2, represents some "main" thread: waitHandle = new…
Jay Lemmon
  • 1,158
  • 1
  • 8
  • 22
0
votes
0 answers

Best Practice EventWaitHandle.Dispose() in Multi-Threaded Environment

I was creating a small logger. For that purpose I have a class (LogFile) which publishes the Log(ILogCsvLine csvLine) method. This method adds the line to log to a queue (linesToLog) and sets a trigger, that has been registered to the ThreadPool…
Der
  • 3
  • 3
0
votes
0 answers

C# Inside one event handler, how to pause execution and wait for a second event to fire?

I have a DLL that return all information asynchronous to several event handler. When I press a button I call a series of functions in the DLL, but the next function should not be called until the previous function has fired the event…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
0
votes
1 answer

Data Repository using MemoryCache

I built a homebrew data entity repository with a factory that defines retention policy by type (e.g. absolute or sliding expiration). The policy also specifies the cache type as httpcontext request, session, or application. A MemoryCache is…
0
votes
1 answer

EventWaitHandle blocking the entire form

I've been looking around for quite some time now, but without any solution.. What I want to achieve, is use an EventWaitHandle class in order to pause one thread. So, I create two buttons on a form. The first one should send a message, then pause,…
Aeder
  • 15
  • 5
0
votes
0 answers

Web Application EventWaitHandle not working after deploying in IIS

I have a web service (WS) and a console application (CA). The WS accepts data and inserts into database. The CA reads this data and performs operations. The synchronization works as follows. The WS has the…
Pazza22
  • 554
  • 3
  • 18
0
votes
0 answers

EventWaitHandle signal reason

Is there any way to determine if an EventWaitHandle was signaled by a call to Set(); or was timed out? an example: private static EventWaitHandle ThreadWaiter = new EventWaitHandle(false, EventResetMode.AutoReset); private void…
Yoav
  • 3,326
  • 3
  • 32
  • 73
0
votes
1 answer

Can I convert while(true) loop to EventWaitHandle?

I'm trying to process large amount of text files via Parallel.ForEach adding processed data to BlockingCollection. The problem is that I want the Task taskWriteMergedFile to consume the collection and write them to result file at least every 800000…
0
votes
2 answers

How to suspend and resume threads

I have a typical Producer/Consumer problem and trying to synchronize 2 Threads. I want to find an alternative to Suspend() and Resume() in C# Compact Framework. They both arent supported by CF :( . I found some examples, which are based on…
0
votes
1 answer

EventWaitHandle - multiple threads = inconsistent behaviour

I am trying to setup some comms with a device where you can send a command and receive a response. I do however want to ensure that I control a timeout flag to prevent indefinite wait times. I did something like this: private volatile…
NubieJ
  • 575
  • 2
  • 9
  • 21
0
votes
2 answers

ManualResetEvent(EventWaitHandle) Set spends much cpu than WaitOne(timeout)

While implementing ManualResetEvent something surprised me, As far as I understand mre.Set() command signals and let other processes to execute. mre.WaitOne(); Holds on the current line and waits for a signal. Beside this if we use it with timeout…
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83
0
votes
2 answers

Are variables assigned from one thread "thread-safe" when read from another thread if an EventWaitHandel is used?

If I create a variable on one thread then block using a ManualResetEvent's WaitOne() method until another thread assigns a value to the same variable and signals the EventWaitHandel. When I come to read the variable on the first thread am I…
markmnl
  • 11,116
  • 8
  • 73
  • 109
0
votes
1 answer

Why does my EventWaitHandle get an UnauthorizedAccessException?

I have coded an executable process that runs the following line of code: immediateShutdownEvent = new EventWaitHandle(false, EventResetMode.ManualReset, "Global\\immediateShutdownEvent", out createdNew, security); I can set this event while this…
Alexandru
  • 12,264
  • 17
  • 113
  • 208
0
votes
2 answers

Scheduling using eventwaithandle

Hi im trying to create an implementation of scheduling using the EventWaitHandle class Take the following example: // Program 1 static void Main(string[] args) { EventWaitHandle wh = new…
Lars Nielsen
  • 436
  • 3
  • 16
0
votes
2 answers

.NET EventWaitHandle signal all threads

Will close() signal all the threads that have called WaitOne()? If not, what's the best way to do this?
poy
  • 10,063
  • 9
  • 49
  • 74