Just like in the old days you should update your time when the application is
idle. For a WinForms app Application.Idle is raised whenever an
application is idle. In Windows an application is considered idle if the
message queue is empty. You should not assume that the idle event is
raised with any sort of frequency. Instead you should update the display
based upon the current time like so.
protected override void OnLoad ( EventArgs e )
{
base.OnLoad(e);
Application.Idle += OnIdle;
}
private void OnIdle ( object sender, EventArgs e )
{
pnlTime.Text = DateTime.Now.ToLongTimeString();
}
An alternative is to set a timer
to go off every second. A timer message is still not completely accurate
as Windows will generate the appropriate message, and hence you'll get the
event, only when no other higher priority messages are in the queue.
Therefore you should still not assume the interval of the events. Here's
an example.
tmrClock.Enabled = true;
tmrClock.Interval = 1000;
tmrClock.Tick += new System.EventHandler(this.OnIdle);