I agree with Bob; if you don't need the features of System.Timers.Timer, you may want to stick with the Windows.Forms timer for UI related events.
On the other hand, if you do need these features, you can force the System.Timers.Timer to invoke the event handler on the UI thread buy setting the Timer.SynchronizingObject property to the instance of the main form. - Krzysztof Cwalina Program Manager, CLR -----Original Message----- From: Moderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Bob Lynch Sent: Sunday, December 28, 2003 6:26 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Timers and Process Monitoring I don't think you want to go down this road. If the only reason for the timer is to update the UI, having a more exact timer doesn't make a lot of sense. The user won't be able to see changes that occur more than about once or twice a second, so the Windows timer is more than adequate. I don't see where you're setting the interval for the timer, but it looks like it might be too short for the UI to keep up with. When you do a BeginInvoke() on a control, it ends up posting a message to the window using a PostMessage() call in User32.dll. My guess is that your interval is short enough that the message queue is getting flooded and so no events from the mouse or keyboard are ever getting through. Is there a reason that you need such high resolution? Regards, Bob -----Original Message----- From: Moderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Grant Sent: Friday, December 26, 2003 11:47 AM To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] Timers and Process Monitoring I have 3 objects in my VB .NET project: 1. DeltaTau wrapped COM object (talking to a PMAC controller over USB) Updates GUI textbox controls with current process status info 2. Vision native .NET object (controlling a vision process over Matrox Mil 7.5) displays a continuous live camera image 3. MainForm .NET form with several wrapped COM objects talking to a DDE Server. Contains a tab control with separate tabs for Vision and DeltaTau The DeltaTau object controls an insertion process that needs monitoring. When complete or on error various bits are set that indicate status. Concurrent with this monitoring the Vision system is acquiring images from a camera system and displaying them on the screen. I started using a System.Timers.Timer for best resolution in my process monitoring in the DeltaTau object. However when I have the System.Timers.Timer enabled my vision object locks up the UI Form. I asked some of the .NET folks around here and was told I need to use BeginInvoke on any function that needs to update the GUI since System.Timers.Timer operates in it's own thread space. Private Sub myDatatimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Dim ActualPosition, CurrentForce, EndingForce, EndingPosition, PeakForce As Single Try ' Live Data ActualPosition = PTalkDT2.DPRGetFloat(GCACTUAL_POSITION_OFFSET) CurrentForce = PTalkDT2.DPRGetFloat(GCFEEDBACK_FORCE_OFFSET) EndingForce = PTalkDT2.DPRGetFloat (GCFORCE_INSERTION_COMPLETE_OFFSET) EndingPosition = PTalkDT2.DPRGetFloat (GCPOSITION_INSERTION_COMPLETE_OFFSET) PeakForce = PTalkDT2.DPRGetFloat(GCPEAK_FORCE_OFFSET) RaiseEvent LiveData(ActualPosition, CurrentForce, EndingForce, EndingPosition, PeakForce) Catch ex As Exception RaiseEvent PMACDPRamReadFailed() Exit Sub End Try End Sub ' Live Data Private Sub DeltaTau2_LiveData(ByVal ActualPosition As Single, ByVal CurrentForce As Single, ByVal EndingForce As Single, ByVal EndingPosition As Single, ByVal PeakForce As Single) Handles DeltaTau2.LiveData BeginInvoke(New DeltaTau1.__Delegate_LiveData(AddressOf LiveData), New Object() {ActualPosition, CurrentForce, EndingForce, EndingPosition, PeakForce}) End Sub Private Sub LiveData(ByVal ActualPosition As Single, ByVal CurrentForce As Single, ByVal EndingForce As Single, ByVal EndingPosition As Single, ByVal PeakForce As Single) ' ensure exclusive access to data SyncLock txtActualPosition.Text txtActualPosition.Text = ActualPosition txtCurrentForce.Text = CurrentForce txtEndForce.Text = EndingForce txtEndPosition.Text = EndingPosition txtPeakForce.Text = PeakForce End SyncLock End Sub However this does not seem to clear up the GUI lock up problem. Any ideas? Thank you, Grant =================================== This list is hosted by DevelopMentorR http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com