Form Updating within Loops
-
Greetings: I am a relatively new C# programmer and I have written a naive little utility which performs a task within a loop. This program is simple and the loop executes inside a routine belonging to the main form. The task that the loop performs does take some time though, maybe a few minutes, depending on various settings. What I wanted, and this is the naive part, was to put some controls on the main form that update the user as to the status of the process. These are mostly just text boxes. When I want to update one or all of the text controls, I write the new string to the control's "Text" property. What I have found though is that the form sometimes updates, but can go into this strange state of limbo where it simply stops updating or sometimes even goes blank. The main loop is still executing and the form will come back to life once the loop is finished. But I wanted the form to update continually throughout the process. I have also found that the form will update itself at first but if I click the mouse pointer on it or attempt to move the form on the display, then it freezes instantly and does not come back until the loop is finished. I am an experienced MFC programmer and I know that this kind of thing happens if you fail to service the "message pump" from within loops of this sort. Have I missed something similar here? Or is this little utility simply an architectural accident-waiting-to-happen? If the later is true, then what must I do to implement a long looping process that provides continually refreshed status to the user interface? Can you point me to books or articles? Thanks in advance to anyone that responds Mark
-
Greetings: I am a relatively new C# programmer and I have written a naive little utility which performs a task within a loop. This program is simple and the loop executes inside a routine belonging to the main form. The task that the loop performs does take some time though, maybe a few minutes, depending on various settings. What I wanted, and this is the naive part, was to put some controls on the main form that update the user as to the status of the process. These are mostly just text boxes. When I want to update one or all of the text controls, I write the new string to the control's "Text" property. What I have found though is that the form sometimes updates, but can go into this strange state of limbo where it simply stops updating or sometimes even goes blank. The main loop is still executing and the form will come back to life once the loop is finished. But I wanted the form to update continually throughout the process. I have also found that the form will update itself at first but if I click the mouse pointer on it or attempt to move the form on the display, then it freezes instantly and does not come back until the loop is finished. I am an experienced MFC programmer and I know that this kind of thing happens if you fail to service the "message pump" from within loops of this sort. Have I missed something similar here? Or is this little utility simply an architectural accident-waiting-to-happen? If the later is true, then what must I do to implement a long looping process that provides continually refreshed status to the user interface? Can you point me to books or articles? Thanks in advance to anyone that responds Mark
-