Question GUI Freezing

TEMPTii

Member
Joined
Aug 29, 2010
Messages
9
Programming Experience
1-3
When I make an application using an HTTPWebRequest to connect to the internet, the GUI freezes whenever it's doing something. When I run the WebRequest on another thread, it still freezes a bit. Is there a way to completely stop the freezing?
 
Any code performed in UI thread eats away at the processing time required to maintain the message loop, which is basically windows event messages. So if you for example do something in UI thread (invoked from an UI event handler) that takes 5 seconds then no messages are processed during that time and UI does not update/respond and appears 'freezed'. When you say 'it still freezes a bit' when doing processing on secondary thread that could mean you are still doing some processing in UI thread unknowingly, or the CPU resources are exhausted for the PC (HttpWebRequest, or normal priority thread would not cause that). It could also be a combination where UI is crammed with controls with large content, perhaps with custom paint handling or other processing, lots of events happening etc.
 
So my best bet is just transferring all of the HTTPWebRequest code into a background worker? Just a thought, can C# handle this better?
 
TEMPTii,
the stuff I'm working on at the moment happened kinda the same.
You have to throw everything that have to "wait for response" on background workers.

My application is handling 2 serial ports and 1 DB processing...
initially only the serial ports were in background workers (each port with it individual worker) and it was still freezing every once in a while...
after I send the DB processing to another bg worker.. then it started flowing nicely.

C# or VB will not make a difference.. it's all .net
 
Back
Top