Painting issue while running two different threads
-
Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..
-
Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..
It sounds as if you've done something very wrong. The form should be on the UI (startup) thread and your worker code on the background thread. If the background isn't doing actual work, it shouldn't normally be running at all, unless this is some kind of server process. It really depends on what you're doing, but it's customary to create the worker background object when needed and let it terminate itself when the work is done, though, that's not always possible or appropriate. The other popular method is to run the background thread in two modes, work and polling. Work mode is obvious. This is where the thread is actually processing work. Polling mode is where the thread is checking some kind of variable every so often to see if there's work to be picked up and processed. This polling should be done in a loop that is delayed with a sleep for, say, once a second. The UI code, your Yes button code, should set the variable appropriately to get the background thread to kick off work.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..