M
Michael C#
Hi all,
I set up a System.Timers.Time in my app. The code basically just updates
the screen, but since the processing performed is so CPU-intensive, I wanted
to make sure it gets updated regularly; like every 1.5 secs. or so. I only
ran into one issue - the MyTimer_Elapsed event handler was not updating the
screen correctly all the time, often leaving large chunks of the screen
un-painted for several seconds.
On a whim I decided to check the InvokeRequired property of my form in the
Event Handler... and whaddyaknow, it was True. So now I've added the proper
code to check InvokeRequired and to update the screen using Invoke(), but I
hadn't realized I needed to use Invoke to update the screen from within the
System.Timers.Timer? Even in the sample MSDN code for the
System.Timers.Timer they leave out the Invoke(); i.e.:
Private Sub myTimer_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)
System.Windows.Forms.MessageBox.Show("Elapsed!", _
"Timer Event Raised!")
End Sub
While I know that Invoke() must be called to update the UI from worker
threads, outside of that is its usage more or less a matter of trial and
error? Or are there additional rules that should be followed when
determining when to use Invoke()?
Just wondering. Thanks.
I set up a System.Timers.Time in my app. The code basically just updates
the screen, but since the processing performed is so CPU-intensive, I wanted
to make sure it gets updated regularly; like every 1.5 secs. or so. I only
ran into one issue - the MyTimer_Elapsed event handler was not updating the
screen correctly all the time, often leaving large chunks of the screen
un-painted for several seconds.
On a whim I decided to check the InvokeRequired property of my form in the
Event Handler... and whaddyaknow, it was True. So now I've added the proper
code to check InvokeRequired and to update the screen using Invoke(), but I
hadn't realized I needed to use Invoke to update the screen from within the
System.Timers.Timer? Even in the sample MSDN code for the
System.Timers.Timer they leave out the Invoke(); i.e.:
Private Sub myTimer_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)
System.Windows.Forms.MessageBox.Show("Elapsed!", _
"Timer Event Raised!")
End Sub
While I know that Invoke() must be called to update the UI from worker
threads, outside of that is its usage more or less a matter of trial and
error? Or are there additional rules that should be followed when
determining when to use Invoke()?
Just wondering. Thanks.