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?
There is no supported way to do that. You have two options:
1) It's best to use System.Timers.Timer
class, 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 between System.Windows.Forms.Timer
, System.Timers.Timer
and System.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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With