autoresetevent

Invocation exception using AutoResetEvent

Hello, C# 2005 I am using a background worker to process some login information. However, the background worker has to stop and wait for 2 events to happen. Once these have finished the background worker can complete its job. They are callbacks that will call the Set() method of the AutoResetEvent. So I am using AutoResetEvent to set ...

Java's equivalent to .Net's AutoResetEvent?

What should I use to get semantics equivalent to AutoResetEvent in Java? (See this question for ManualResetEvent). ...

C# Threading issue with AutoResetEvent

How to properly synchronize this? At the moment it is possible thatSetData is called after e.WaitOne() has completed so d could be already set to another value. I tried to insert locks but it resulted into a deadlock. AutoResetEvent e = new AutoResetEvent(false); public SetData(MyData d) { this.d=d; e.Set(); // notify that ne...

Whats wrong with my AutoResetEvent code?

Hi, I have this code which seems pretty straightforward but the AutoResetEvent never gets signalled. Nothing seems to get returned from the web services and the WaitAll just times out after ten seconds. Everything works fine without the threading jiggerypokery so its not a web service issue. What am I doing wrong? AutoResetEvent[] a...

Does AutoResetEvent.WaitOne() frees a slot in the thread pool?

I am trying to synchronize an asynchronous method. The main advantage of the async version is that it frees a slot in the thread pool. I would like to keep this advantage in my sync version. When I use AutoResetEvent.WaitOne() it is equivalent to a Thread.Sleep() in terms of thread pool usage? ...

AutoResetEvent object , waits 60 secs OR event

Im using AutoResetEvent object to block a thread for 60 secs ,, but I would like to block it for 60 secs or AutoResetEvent.set() event CODE : global: private readonly AutoResetEvent _signal = new AutoResetEvent(false); blocking: _signal.WaitOne(60000, true); event to give signal _signal.Set(); but it alwayas waits the whole 60 se...

Get signalled when a file handle is acquired

What's the best way for getting signalled (similar to AutoResetEvent) when an exclusive handle to a file is acquired? (e.g. at the end of a huge file copy) ...

Queues And Wait Handles in C#

I've had the following code in my application for some years and have never seen an issue from it. while ((PendingOrders.Count > 0) || (WaitHandle.WaitAny(CommandEventArr) != 1)) { lock (PendingOrders) { if (PendingOrders.Count > 0) { fbo = PendingOrders.Dequeue(); } else { ...

Lightweight alternative to Manual/AutoResetEvent in C#

Hi, 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 the code seems to work well in both testing and production, getting this kind of th...

Unit-test passes in Debug, but hangs when Run

I have an odd problem. I have a unit test that keeps getting stuck in Run Mode. When I run the same test in Debug, with no breakpoints, the test passes every time. Basically, it is a socket connection test. I first disconnect a socket, and then try to reconnect, and I am trying to check if the reconnection was successful. Somewhere in...

AutoResetEvent not blocking properly

Hi guys, I have a thread, which creates a variable number of worker threads and distributes tasks between them. This is solved by passing the threads a TaskQueue object, whose implementation you will see below. These worker threads simply iterate over the TaskQueue object they were given, executing each task. private class TaskQueue :...

Is the AutoResetEvent type an appropriate choice for an atomic switch?

Suppose I am processing a large amount of incoming data from multiple threads. I may want for this data to act as a trigger for a specific action when certain criteria are met. However, the action is not reentrant; so the same trigger being fired twice in rapid succession should only cause the action to run once. Using a simple bool fla...

How to avoid Safe handle has been closed

I have the following code in a test: private void LoadIncomeStatementViewModel() { using (var evt = new AutoResetEvent(false)) { EventHandler handler = (sender, e) => evt.Set(); _incomeStatementViewModel.Loaded -= handler; _incomeStatementViewModel.Loaded += handler; ...