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
RobinS - 13 Feb 2007 02:54 GMT
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.
----------------------------------------------
> Hi All,
>
[quoted text clipped - 24 lines]
> Thanks,
> Brian
Otis Mukinfus - 13 Feb 2007 03:35 GMT
>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
[quoted text clipped - 3 lines]
>
>Robin S.
[snip]
What if the cursor wasn't an arrow to start with?
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
PhilipDaniels@foo.com - 13 Feb 2007 09:28 GMT
>So, how does one accomplish this "technique" properly in C#/Winform/.NET2?
>
[quoted text clipped - 8 lines]
>Thanks,
>Brian
At a rudimentary level, you may want to try placing your code in the
"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
Linda Liu [MSFT] - 13 Feb 2007 09:57 GMT
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.
David W - 14 Feb 2007 18:47 GMT
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
> Hi Brian,
>
[quoted text clipped - 46 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Linda Liu [MSFT] - 16 Feb 2007 10:57 GMT
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
Jeffrey Tan[MSFT] - 20 Feb 2007 04:06 GMT
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.