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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A ManualResetEvent doesn’t have a wait state. The only thing that can wait on an MRE is a thread. And yes, a thread consumes plenty of precious resources needlessly when it is not doing what it was made to do, execute code. A megabyte of virtual memory and a handful of kernel objects. The single kernel object that MRE consumes is small potatoes compared to that.
You typically want to use a threadpool thread instead.
And look at what’s available in .NET 4.0. Like ManualResetEventSlim (not based on an OS object) and the Task class.