|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
.NET C# Winforms question about window openingI think I have a question that probably has an easy answer, but I can't manage to find it. I come from a Sybase PowerBuilder programming background, and pretty much all PB developers used the following technique: "Post"ing a method/event when opening a window, so that the window displays, is drawn, an hourglass displays, and then run any code that may take a while (i.e. a long query retrieval). As opposed to, putting the retrieval (or whatever) code in the Open event, which would show the user nothing, and give them the impression that "nothing" was happening. Until the query is retrieved, then the window will be displayed. So, how does one accomplish this "technique" properly in C#/Winform/.NET2? I've currently got a winform and in the Load event I'm calling a webservice. This webservice can take awhile to return with the necessary data. Thus my window isn't displayed until the WS returns data. I would rather the window displays, shows an hourglass, then calls the web service, and the program waits until it returns. Any suggestions? Thanks, Brian Why don't you just change the cursor to the hourglass when calling the
webservice, and set it back when it's finished? IIRC, try typing this in to the code window of the form this.Cursor = Cursors.WaitCursor; and this.Cursor = Cursors.Arrow; Robin S. ---------------------------------------------- Show quoteHide quote "Brian Simmons" <centraso@newsgroup.nospam> wrote in message news:ekLEgwwTHHA.4276@TK2MSFTNGP02.phx.gbl... > Hi All, > > I think I have a question that probably has an easy answer, but I can't > manage to find it. > > I come from a Sybase PowerBuilder programming background, and pretty much > all PB developers used the following technique: > "Post"ing a method/event when opening a window, so that the window > displays, is drawn, an hourglass displays, and then run any code that may > take a while (i.e. a long query retrieval). > As opposed to, putting the retrieval (or whatever) code in the Open > event, which would show the user nothing, and give them the impression > that "nothing" was happening. Until the query is retrieved, then the > window will be displayed. > > So, how does one accomplish this "technique" properly in > C#/Winform/.NET2? > > I've currently got a winform and in the Load event I'm calling a > webservice. This webservice can take awhile to return with the necessary > data. Thus my window isn't displayed until the WS returns data. I would > rather the window displays, shows an hourglass, then calls the web > service, and the program waits until it returns. > > Any suggestions? > > Thanks, > Brian > On Mon, 12 Feb 2007 18:54:35 -0800, "RobinS" <RobinS@NoSpam.yah.none> wrote: What if the cursor wasn't an arrow to start with?>Why don't you just change the cursor to the hourglass when calling the >webservice, and set it back when it's finished? IIRC, try typing this in >to the code window of the form > this.Cursor = Cursors.WaitCursor; >and this.Cursor = Cursors.Arrow; > >Robin S. [snip] Cursor cursor = this.Cursor; this.Cursor = Cursors.WaitCursor; // do something... this.Cursor = cursor; Good luck with your project, Otis Mukinfus http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com On Mon, 12 Feb 2007 20:12:53 -0500, "Brian Simmons"
<centraso@newsgroup.nospam> wrote: >So, how does one accomplish this "technique" properly in C#/Winform/.NET2? At a rudimentary level, you may want to try placing your code in the> >I've currently got a winform and in the Load event I'm calling a webservice. >This webservice can take awhile to return with the necessary data. Thus my >window isn't displayed until the WS returns data. I would rather the window >displays, shows an hourglass, then calls the web service, and the program >waits until it returns. > >Any suggestions? > >Thanks, >Brian > "Shown" event. This occurs later, and is fired when the form is actually on the screen. (The sequence of events is Load, Activated, Shown). If you want to do stuff "in the background" then you will need to look into asynchronous calls. -- Philip Daniels Hi Brian,
I agree with you that it's better to show the main window first, and then calls the web serive. When a program is going to execute some time-consuming work, it would be a pleasant user experience to show the progress of the underlying work, besides showing an hourglass cursor. .NET 2.0 has provided the BackgroundWorker class which makes this task easy. So I suggest that you use a BackgroundWorker component in your form and start the underlying work when the form is loaded. When the underlying work is being executed, you may show an hourglass cursor and disable some controls on your form if necessary. For more information on BackgroundWorker and how to use it, you may visit the following link. 'BackgroundWorker Class' http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundwor ker.aspx Hope this helps. If you have any question, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Alternately, you can put a timer control on the form and set it for an
interval of 5 or something. Then fire off your web service from the timer event. Just remember to disable the timer first thing in the timer event. -Dave Show quoteHide quote "Linda Liu [MSFT]" <v-l***@online.microsoft.com> wrote in message news:rii5XV1THHA.3604@TK2MSFTNGHUB02.phx.gbl... > Hi Brian, > > I agree with you that it's better to show the main window first, and then > calls the web serive. > > When a program is going to execute some time-consuming work, it would be a > pleasant user experience to show the progress of the underlying work, > besides showing an hourglass cursor. .NET 2.0 has provided the > BackgroundWorker class which makes this task easy. > > So I suggest that you use a BackgroundWorker component in your form and > start the underlying work when the form is loaded. When the underlying > work > is being executed, you may show an hourglass cursor and disable some > controls on your form if necessary. > > For more information on BackgroundWorker and how to use it, you may visit > the following link. > > 'BackgroundWorker Class' > http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundwor > ker.aspx > > Hope this helps. > If you have any question, please feel free to let me know. > > > Sincerely, > Linda Liu > Microsoft Online Community Support > > ================================================== > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications. > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > http://msdn.microsoft.com/subscriptions/support/default.aspx. > ================================================== > > This posting is provided "AS IS" with no warranties, and confers no > rights. > Hi Brian,
How about the problem now? If you have any question, please feel free to let us know. Thank you for using our MSDN Managed Newsgroup Support Service! (BTW, I will be on a long vacation from the next Monday to Friday. During my leave, my team mates will follow up with you and it may not in time. Sorry for the inconvenience it may bring to you!) Sincerely, Linda Liu Microsoft Online Community Support Hi Brian,
Since my colleague Linda is on vacation this week, I will continue to work with you. How about this issue now? Does Linda's reply make sense to you? If you still need any help, please feel free to feedback, thanks. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Other interesting topics
TypeConverter question
toolstrip container backcolor and gradients - I want it to look like outlook 2003! OT: Crossword Puzzle Creator - .NET Source GroupBox and/or Tab Control Font Colours MDI app - don't load document twice Resize nested control at runtime A Label control that its text can be selected with the mouse Need help on some PropertyGrid and PropertyGridView members Displaying a status image in a datagridview Setting a style for a selected row in the DataGridView |
|||||||||||||||||||||||