Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value of a System.Windows.Forms.Timer?

Having a little problem with the windows form timer. Its a very basic question, but I've looked around and cannot seem to find the answer (I probably deserve a slap).

I need to be able to get the value of the timer, whether its elapsed time is greater than an interval of 500ms.

something like

Timer.Elapsed >= 500
like image 784
ConsultingEasy Avatar asked Nov 29 '22 13:11

ConsultingEasy


1 Answers

Timer.Elapsed isn't a property returning "the elapsed time" - it's an event you subscribe to. The idea is that the event fires every so often.

It's not really clear whether you even want a Timer - perhaps System.Diagnostics.Stopwatch is really what you're after?

var stopwatch = Stopwatch.StartNew();
// Do some work here

if (stopwatch.ElapsedMilliseconds >= 500)
{
    ...
}
like image 112
Jon Skeet Avatar answered Dec 05 '22 01:12

Jon Skeet