Solved Background worker stops and form turns white.

September 23, 2013 at 06:49:11
Specs: Windows 7, 2.4ghz xenon
I have created a program that schedules items. About every 2 seconds it updates the form by getting new data from the MSSQL server. After the application gets through about 700 updates the background worker stops running the loop and just gets stuck. It does not throw up an error but the part of the form that gets updated turns white. I have put everything in my background worker in a try catch statement but that does not get raised when it stops. Any suggestions?

EDIT: If stop the background worker every 500 or so updates and then start it again I do not get that error. Inside of the background worker I have it running multiple SQL queries which all of them are getting disposed properly. It also creates components and adds them to the form if needed

Note: The last thing to show in my Immediate Window is

"A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll"

message edited by rocky3598


See More: Background worker stops and form turns white.

Report •


✔ Best Answer
September 27, 2013 at 12:06:02
I figured out what was going on. I had a handler leak. It was maxing out the handles and crashing the thread.


#1
September 25, 2013 at 13:15:06
Does your background worker completion routine run? If so, what error do you capture in your RunWorkerCompletedEventArgs.Error?

How To Ask Questions The Smart Way


Report •

#2
September 26, 2013 at 08:20:38
No it does not. I have it in a 2 second loop. Every 2 seconds the background worker is instructed to run a query from the MSSQL server and report any differences which are then reflected on the form. At first I thought it was because of a multi-threading issue but I have double checked every cross thread call and they are all safe thread calls using a delegate and an invoke method. I also found out the the number of loops before it fails is proportional to the number of components on the form. The more components the less loops it takes to fail.

Report •

#3
September 26, 2013 at 09:45:57
It sounds like a race bug, but I'd need to see the code. Make sure any data shared between the background worker and the GUI thread is thread safe. If it's not, you'll need to use locks to make it safe.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
September 27, 2013 at 12:06:02
✔ Best Answer
I figured out what was going on. I had a handler leak. It was maxing out the handles and crashing the thread.

Report •

Ask Question