new AutoResetEvent(false).WaitOne(Period);
What is purpose of this code? Why not use Thread.Sleep instead?
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.
Yes, that code is stupid. Since the
AutoResetEventisnewin this line, nothing else has a reference to the sameAutoResetEvent, so nothing is going to signal it. ASleepwould be simpler.When used correctly, use of an
AutoResetEventallows you to wait for something else to “open the gate” (assuming it wasn’t already open), or timeout. Note also that the gate closes automatically each timeWaitOneis successful.However, this code does not use it correctly, and does not allow for this.