Is there a way to build a new timer with a given action, but tell it from the start that it must kill itself after one hour? (Can it work it out by itself or do I need another line to handle that?)
Share
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.
I’d use two timers, one to do whatever you want and the other to kill the first timer after an hour.
Here are two examples, each using a 1 second primary timer that needs to be killed at the fifth second.
If you are using System.Threading.Timer:
If you are using System.Timers.Timer:
All times are in milliseconds (1000 in a second).
System.Threading.Timeris preferred according to this post, butSystem.Timers.Timeris for situations where the timer’s methods may be called from different threads, according to this post.