Control does not redraw after loosing and regaining focus
-
Hi there, C# experts! I have a (in my view actually simple) problem: In my application I want to wait for a predefined timespan and show this to the user via a progress bar. However, I want to call the waiting method from my business logic class rather than from my GUI class. Therefor I use following simple code: public void Wait4Something() { // Timespan we want to wait... int Wtime = 60; // myBar is the progress bar owned by the form. // "this" is NOT the form but a motor class // driving the form and driven by form events. if( this.myBar != null ) { this.myBar.Value = 0; this.myBar.Maximum = Wtime; this.myBar.Step = 1; } this.myGUI.Refresh(); for ( int i = 0; i < Wtime; i += 1 ) { this.SomeOtherObject.Wait4BroadcastReply( (uint) 1000 ); this.myBar.PerformStep(); // Proceed with the progress bar this.myGUI.Refresh(); // <- this does not do apparently } if( this.myBar != null ) this.myBar.Value = 0; } However, if I let the code run, everything is fine until I hit [ALT]-[TAB] to swap windows and then hit it again to swap back to my app. By then, the GUI freezes, shows the hourglass and does not redraw or revalidate and the progress bar does not do steps either. After the specified waiting time, the control returns to normal and reacts to every event as expected. I could probably dissolve the whole thing by starting a new thread, but i hoped not to get forced to do this for a simple visualization of waiting :/ Does anyone know of a feasible solution?? Thanks in advance for your regard, Udo "You can do it that way or that way. I like it that way."
-
Hi there, C# experts! I have a (in my view actually simple) problem: In my application I want to wait for a predefined timespan and show this to the user via a progress bar. However, I want to call the waiting method from my business logic class rather than from my GUI class. Therefor I use following simple code: public void Wait4Something() { // Timespan we want to wait... int Wtime = 60; // myBar is the progress bar owned by the form. // "this" is NOT the form but a motor class // driving the form and driven by form events. if( this.myBar != null ) { this.myBar.Value = 0; this.myBar.Maximum = Wtime; this.myBar.Step = 1; } this.myGUI.Refresh(); for ( int i = 0; i < Wtime; i += 1 ) { this.SomeOtherObject.Wait4BroadcastReply( (uint) 1000 ); this.myBar.PerformStep(); // Proceed with the progress bar this.myGUI.Refresh(); // <- this does not do apparently } if( this.myBar != null ) this.myBar.Value = 0; } However, if I let the code run, everything is fine until I hit [ALT]-[TAB] to swap windows and then hit it again to swap back to my app. By then, the GUI freezes, shows the hourglass and does not redraw or revalidate and the progress bar does not do steps either. After the specified waiting time, the control returns to normal and reacts to every event as expected. I could probably dissolve the whole thing by starting a new thread, but i hoped not to get forced to do this for a simple visualization of waiting :/ Does anyone know of a feasible solution?? Thanks in advance for your regard, Udo "You can do it that way or that way. I like it that way."
An Application.DoEvents() call instead (or additional) to the Refresh could do the job. But note that you then probably have to disable the form because it will react to user input. A seperate thread would be better...
-
An Application.DoEvents() call instead (or additional) to the Refresh could do the job. But note that you then probably have to disable the form because it will react to user input. A seperate thread would be better...
Hi Robert, thanks for your instant help, I was afraid of it but in the end it's probably best to do it right in the first place. So I'll be weaving some threads... Thanks, Udo ---- Anyway, Application.DoEvents() did help as a hotfix, and as I'm not doing anything mutual it's probably harmless to let the GUI react to user input, if not wanted. So thanks again for your very helpful advice!