I use a System.Threading.Timer object, and I set its period:
// period of 1 second
var timer = new Timer(CallBack, null, 0, 1000);
...
Now I want to get the period of my timer, how can I do?
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.
There is no supported way to do that. You have two options:
1) It’s best to use
System.Timers.Timerclass, as it’s more flexible, and safer to use in case of multi threaded use. If you want to know more about timers, and comparison betweenSystem.Windows.Forms.Timer,System.Timers.TimerandSystem.Threading.Timer, please read MSDN article about this subject.2) Use reflection to access private member holding the period value. There are plenty of nice articles on how to do this, and you can use ILSpy to see which field you need to read. (it’s timer.m_timer.m_timer.m_period in .NET 4.0, it may be the same in other versions too)