how to stop a timer at a given time? say 10mins?
How to stop a timer at a given time in C#?
Collapse
X
-
Tags: None
-
Get the value of DateTime.Now before you start it and store it somewhere like a variable called startTime. Then check to see if (DateTime.Now - startTime).Tota lMinutes is greater than 10.
(NOTE: Subtracting, or adding, two DateTime values results in a TimeSpan object) -
I should also mention, if your timer is ticking every X seconds/minutes but you want to turn it off after exactly 10, you could always use a second timer. Create it, set the interval to whatever your timeout is, then turn both timers off when the second timer ticks.
Whatever works best for you.Comment
Comment