Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • System.Windows.Forms.Timer - Reading current state / time
AuthorQuestion
System.Windows.Forms.Timer - Reading current state / time
Posted on: 24 Dec 2010

Hi there,
I use several interval timers (System.Windows.Forms.Timer).
To debug and analyze, I wish to read (and display)  current time (ticks) of a timer after it has been started, and while counting down.
Does anyone know of a way to read / display the timer while running?
Thanks,
Sam

AuthorReply
Re: System.Windows.Forms.Timer - Reading current state / time
Posted on: 24 Dec 2010  
I doubt it is possible to get that from the Timer class, since it does not need that information. Of course you have not made clear what you mean by ticks; I assume a tick is defined as being the equivalent of the firing of the Timer.Tick event. The Timer class has no use of counting the number of such events that has happened.
Thinking is a feeling; pleasant for some and unpleasant for others.
Re: System.Windows.Forms.Timer - Reading current state / time
Posted on: 24 Dec 2010  

//timer1 interval = 1000   (1 sec)

int t1count = 0;
private void timer1_Tick(object sender, EventArgs e)
{
t1count++;
label1.Text = (
"timer1 = " + Convert.ToString(t1count));
}

Sam
  • 0
  • 0
Re: System.Windows.Forms.Timer - Reading current state / time
Posted on: 26 Dec 2010  

Hello Sam Hobbs,


I am aware of the fact that there is no direct property that will indicate a timer's 'current' state in terms of elapsed time, which is actually what I am looking for.
I have a Timer Enabled (Started) and I wish to know (1) if it is actually running and (2) its momentary current position relative to its start time (This is the timer's elapsed time or the time left to raise the event).  
The only 'ugly' way of doing it is by starting simultanuesly a recycling fractional internal timer (like 100mSec) and use its output to get the main timer elapsed.
The problem is that such option does not indicate if the outer main timer is actually running. 
(There is a virtual method IsTimerRunning that can be used for that, but I am not sure how to use it). 
I needed it mainly for debugging, but I can be without, although I think it could be a nice feature to use.
Sam

Sam
  • 0
  • 0
Re: System.Windows.Forms.Timer - Reading current state / time
Posted on: 26 Dec 2010  

Hello Frogleg,
Thanks.
I think your solution will give me a one second timer which is not exactly what I am looking for.
Please see my previous reply to Sam Hobs where my question is better described.
Sam

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.