|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Unresponsive UI during lengthy operation ?I'm making a Windows application that does some lengthy retrieval operations from a database and possibly from a internet resource. I want to show that the operation is going on, by using an Animated .gif in a picture box. Also note that this PictureBox also acts as the button to invoke this lengthy operation. In other words, the user will click the PicBox to start the operation. When clicked, I update the Image property of the PicBox to the Animated .gif, and then call the lengthy method. I also change the Tooltip of the PicBox to something like "Retrieving... please wait...". At the end of the operation, I want to reset the Image property of the PicBox. The problem is that the PicBox image just freezes until the operation is complete, by then it is already time to reset the Image. How do I show the progress in this case ? The tooltip however, gets changed, which means that the problem is mainly with updating the image. I have also noticed that the form will not repaint, if I bring another application over it, and restore it. I have tried to call Application.DoEvents() at the start of my lengthy method, but it never seems to have any effect whatsoever. My concepts are a bit shaky as far as Asynchronous calls are concerned, so I was wondering if there is any other way to prevent the UI from freezing up. Any help is appreciated. Regards, Cerebrus. Just to add a question...
Is Multi-threading the only answer Regards, Cerebrus. > Is Multi-threading the only answer Yes, in my opinion. Run the lengthy operation on a new thread. Devise a mechanism for communication between the new thread and the ui thread. There are two easy choices. 1. Worker thread updates properties in a class or module with synclock, ui thread has a timer and samples them regularly also using synclock. 2. Worker thread posts info to ui thread directly via invoke or begininvoke/endinvoke. Probably #2 is most commonly used, I prefer #1. well there are two ways i would recomend
1. use multithreading ( start a seperate thread ,,,, Background worker would be suitable for this ) 2. start the operation asynchronous if it supports this feature ( webservices and database objects often provide a begin and end invoke ) maybe someone else has other options regards Michel Posseth [MCP] Show quoteHide quote "Cerebrus99" <zorg***@sify.com> wrote in message news:utRgJRiMGHA.1180@TK2MSFTNGP09.phx.gbl... > Hi all, > > I'm making a Windows application that does some lengthy retrieval > operations > from a database and possibly from a internet resource. > > I want to show that the operation is going on, by using an Animated .gif > in > a picture box. Also note that this PictureBox also acts as the button to > invoke this lengthy operation. In other words, the user will click the > PicBox to start the operation. When clicked, I update the Image property > of > the PicBox to the Animated .gif, and then call the lengthy method. I also > change the Tooltip of the PicBox to something like "Retrieving... please > wait...". At the end of the operation, I want to reset the Image property > of > the PicBox. > > The problem is that the PicBox image just freezes until the operation is > complete, by then it is already time to reset the Image. How do I show the > progress in this case ? The tooltip however, gets changed, which means > that > the problem is mainly with updating the image. I have also noticed that > the > form will not repaint, if I bring another application over it, and restore > it. > > I have tried to call Application.DoEvents() at the start of my lengthy > method, but it never seems to have any effect whatsoever. > > My concepts are a bit shaky as far as Asynchronous calls are concerned, so > I > was wondering if there is any other way to prevent the UI from freezing > up. > > Any help is appreciated. > > Regards, > > Cerebrus. > > See:
Resources about asynchronous operations http://www.mztools.com/resources_net_developers.htm#AsynchronousOperations -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Cerebrus99" <zorg***@sify.com> escribió en el mensaje news:utRgJRiMGHA.1180@TK2MSFTNGP09.phx.gbl... > Hi all, > > I'm making a Windows application that does some lengthy retrieval > operations > from a database and possibly from a internet resource. > > I want to show that the operation is going on, by using an Animated .gif > in > a picture box. Also note that this PictureBox also acts as the button to > invoke this lengthy operation. In other words, the user will click the > PicBox to start the operation. When clicked, I update the Image property > of > the PicBox to the Animated .gif, and then call the lengthy method. I also > change the Tooltip of the PicBox to something like "Retrieving... please > wait...". At the end of the operation, I want to reset the Image property > of > the PicBox. > > The problem is that the PicBox image just freezes until the operation is > complete, by then it is already time to reset the Image. How do I show the > progress in this case ? The tooltip however, gets changed, which means > that > the problem is mainly with updating the image. I have also noticed that > the > form will not repaint, if I bring another application over it, and restore > it. > > I have tried to call Application.DoEvents() at the start of my lengthy > method, but it never seems to have any effect whatsoever. > > My concepts are a bit shaky as far as Asynchronous calls are concerned, so > I > was wondering if there is any other way to prevent the UI from freezing > up. > > Any help is appreciated. > > Regards, > > Cerebrus. > > "Cerebrus99" <zorg***@sify.com> schrieb: Multithreading in Windows Forms applications> My concepts are a bit shaky as far as Asynchronous calls are concerned, so > I > was wondering if there is any other way to prevent the UI from freezing > up. <URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Thank you very much everyone for all that information !
I have now realized that knowledge of Multithreading and Asynchronous operations were one area that I cannot do without. So, I have read up on some of those useful links (Thanks for Carlos and Herfried). I have now been able to implement the following in my application : 1. The Click of the PicBox now starts an asynchronous process to retrieve all the data. 2. During this operation, the UI remains responsive and the PicBox shows an Animating .gif. 3. I have learned not to violate the prime directive of Windows Thread programming-"Though shalt not operate on a window from other than its creating thread." Basically to use the Invoke method. Some minor flaws remain, and I turn to you again for advice... 1. At the start of the operation, I changed the Cursor to Cursors.WaitCursor, and I change it back to Cursors.Default after the operation completes. But my Cursor changes almost immediately to the Default cursor, even though the line instructing it to be set to Default, is reached only later in the processing. Is this behaviour changeable too ? I want to keep showing an Hourglass while processing continues. 2. The retrieval operation seems to take longer than before. Is this normal, or just a psychological reaction of mine ? :-) Thanks again, folks, Regards, Cerebrus.
extending BackgroundWorker ProgressChangedEventArgs
Invoking a PictureBox click ? MethodInfo or MethodBase? Random number problem Percentages Need to resize label height automatically. listview checkbox column - toggle image ThreadPool.QueueUserWorkItem console.write Noob Question - Best Control for a TV Guide? |
|||||||||||||||||||||||