I need some help trying to debug a slow repaint issue with one of my Vb. Net WinForms programs. When the program is first started the screens repaint just fine. After the program has ran for a few hours, you can start to notice the screens taking longer to repaint. After the program has run for over 24 hours, the screen repaint takes about 10 seconds. It eventually gets to a point where it gets so slow that you have to shut the program down and restart it. After restarting the program, the program screens repaint fast again but then start to slow down the longer the program runs. I’ve read that slow repaint can occur on Forms that have many controls. The most complex form I have has about 100 controls and does not include a lot of control nesting.
I have this same program running on multiple computers which use 2 different operating systems. Most of the computers are running Windows 2000 SP4 but we also have a couple running Windows XP. The slow repaint issue only happens on the computers running Windows 2000.
I first thought I had a memory leak with some of my GDI objects so I ran GDI view and found a few small issues that I have since corrected. Now when the program runs, there is rarely over 100 GDI objects open at any time and it doesn’t seem like its creeping up anymore.
When I was doing some my testing, I noticed what I first thought was a handle leak. I left the task manager open and I noticed that the handles went up to about 1500 but then reset back down to 500. I did some investigating and discovered that the handles increased anytime the background thread fired an event that updated the GUI thread via invoke. The background thread in my program constantly captures the same data from an external process every few seconds. I have the background thread running in a Do while loop. Is it normal for the handles to increase like that? This is my first project using a continuously operating background thread so I’m a little green at doing this. Here is my code for updating the GUI thread:
Public Sub SetText(ByVal ctrl As Control, ByVal text As String)
'This sub updates the text to the required control
If ctrl.InvokeRequired Then
ctrl.Invoke(New SetTextDelegate(AddressOf SetText), ctrl, text)
Else
ctrl.Text = text
End If
End Sub
When I tracked the number of handles on the Windows 2000 system, the handles started out at over 7000 right when I started the program but then stayed very steady. Does anyone know why there is such a big difference in the number of handles reported by task manager on the 2 different systems? Are they reporting the same thing?
Does anyone have any other ideas on what is causing the screen repaint to slow down? Since I’m not having the issue on the XP systems, could it be something as simple as adding more memory to the Windows 2000 systems?