waithandle

Conditional periodic timer using wait handles

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:42:36
问题 I need a timer equivalent which will periodically execute some specific actions (e.g. updating some progress in the database or checking for new Jobs to execute in a database). These actions are bound to a WaitHandle which specifies if the job needs to be executed or not. So basically this could be, for example, an AutoResetEvent which is set from outside when there is a new Entity in a database and trigger the search for these new Entities. The timer is necessary because I want to limit the

Awaiting server responses in an async way to different calls at the same time

有些话、适合烂在心里 提交于 2019-12-11 04:57:56
问题 I am writing a client library for a model railway controller over TCP. The server is embedded in the control unit. When the client sends a command to the server, for example set(5, addr[3]) the server responds with a reply header <REPLY set(5, addr[3])> , results for that command and if there was an error. Because all this stuff is asynchronous, I have to match the replies with the commands. (Even if the client would only send one command and then wait for the response there are serverside

C# Async WebRequests: Perform Action When All Requests Are Completed

只谈情不闲聊 提交于 2019-12-03 21:12:36
I have this basic scraping console application in C# that Asynchronously uses WebRequest to get html from a list of sites. It works fine, but how do I set up a trigger that goes off when every site in the list has been processed? I've spent a couple hours researching various solutions online, including the MS docs, but none of them provide a straight forward answer via code. I've read about the IAsyncResult.AsyncWaitHandle but I have no clue how to integrate it into my code. I'd just like to call a custom function when all threads complete processing or timeout. One trick is that I never know

WaitHandle.WaitAny and Semaphore class

一个人想着一个人 提交于 2019-11-29 21:37:09
问题 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 type can have (say) 10 instances at any time. When one of either types of resources becomes available, my worker thread needs to wake up (there is a variable number of threads). In an earlier implementation, there was only one resource type, for

What is the difference between Thread.Sleep(timeout) and ManualResetEvent.Wait(timeout)?

一曲冷凌霜 提交于 2019-11-28 20:49:05
Both Thread.Sleep(timeout) and resetEvent.Wait(timeout) cause execution to pause for at least timeout milliseconds, so is there a difference between them? I know that Thread.Sleep causes the thread to give up the remainder of its time slice, thus possibly resulting in a sleep that lasts far longer than asked for. Does the Wait(timeout) method of a ManualResetEvent object have the same problem? Edit : I'm aware that a ManualResetEvent's main point is to be signaled from another thread - right now I'm only concerned with the case of an event's Wait method with a timeout specified, and no other

Do I need to call Close() on a ManualResetEvent?

瘦欲@ 提交于 2019-11-27 03:51:42
问题 I've been reading up on .NET Threading and was working on some code that uses a ManualResetEvent. I have found lots of code samples on the internet. However, when reading the documentation for WaitHandle, I saw the following: WaitHandle implements the Dispose pattern. See Implementing Finalize and Dispose to Clean Up Unmanaged Resources. None of the samples seem to call .Close() on the ManualResetEvent objects they create, even the nice Recursion and Concurrency article from the pfxteam blog

Workaround for the WaitHandle.WaitAll 64 handle limit?

泪湿孤枕 提交于 2019-11-26 08:02:42
问题 My application spawns loads of different small worker threads via ThreadPool.QueueUserWorkItem which I keep track of via multiple ManualResetEvent instances. I use the WaitHandle.WaitAll method to block my application from closing until these threads have completed. I have never had any issues before, however, as my application is coming under more load i.e. more threads being created, I am now beginning to get this exception: WaitHandles must be less than or equal to 64 - missing