Re: Long Process
- From: Tom Shelton <tom_shelton@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 May 2008 11:27:25 -0700
On 2008-05-21, John Wright <riley_wright@xxxxxxxxxxx> wrote:
This is a multi-part message in MIME format.
------=_NextPart_000_0354_01C8BB3B.79B811B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I have a long process I run that needs to be complete before the user =
can continue. I can change the cursor to an hourglass, but I want to =
update the Status Strip on the bottom during the process. I set the =
statusstrip label to "Downloading...", but it will not show up on the =
form. I need to display this message before it starts the process. I =
can put a thread.sleep for 1 second after I do the initial process, but =
that seems sloppy to me. Any suggestions? Here is my code launched =
from a button click:
'update the label--This does not show because the process starts before =
the UI updates
slDBList.Text =3D "Retrieving Databases..."TryMe.Cursor =3D =
Cursors.WaitCursorDim lstServers As List(Of String)'set to false in case =
of an error boolServersLoaded =3D FalseboolDBLoaded =3D False'clear the =
servers list cbServers.DataSource =3D Nothing'clear the databases list =
dbDatabases.DataSource =3D NothingIf chkSort.Checked =3D True =
ThenlstServers =3D GetSqlServers(True)ElselstServers =3D =
GetSqlServers(False)End IfcbServers.DataSource =3D lstServers'set to =
true to enabled the selected index change on the dropdown =
boolServersLoaded =3D TrueslDBList.Text =3D ""Catch ex As =
ExceptionMessageBox.Show("Error loading server list. Error: " & =
ex.ToString, "Data Error", MessageBoxButtons.OK, =
MessageBoxIcon.Error)boolServersLoaded =3D FalseslDBList.Text =3D =
""FinallyMe.Cursor =3D Cursors.ArrowEnd Try
------=_NextPart_000_0354_01C8BB3B.79B811B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3314" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I have a long process I run that needs =
to be=20
complete before the user can continue. I can change the cursor to =
an=20
hourglass, but I want to update the Status Strip on the bottom during =
the=20
process. I set the statusstrip label to "Downloading...", but it =
will not=20
show up on the form. I need to display this message before it =
starts the=20
process. I can put a thread.sleep for 1 second after I do the =
initial=20
process, but that seems sloppy to me. Any suggestions? Here =
is my=20
code launched from a button click:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>'update the label--This does not show =
because the=20
process starts before the UI updates</FONT></DIV><PRE>slDBList.Text =3D =
"Retrieving Databases..."</PRE><PRE>Try</PRE><PRE>Me.Cursor =3D =
Cursors.WaitCursor</PRE><PRE>Dim lstServers As List(Of =
String)</PRE><PRE>'set to false in case of an error =
</PRE><PRE>boolServersLoaded =3D False</PRE><PRE>boolDBLoaded =3D =
False</PRE><PRE>'clear the servers list </PRE><PRE>cbServers.DataSource =
=3D Nothing</PRE><PRE>'clear the databases list =
</PRE><PRE>dbDatabases.DataSource =3D Nothing</PRE><PRE>If =
chkSort.Checked =3D True Then</PRE><PRE>lstServers =3D =
GetSqlServers(True)</PRE><PRE>Else</PRE><PRE>lstServers =3D =
GetSqlServers(False)</PRE><PRE>End If</PRE><PRE>cbServers.DataSource =3D =
lstServers</PRE><PRE>'set to true to enabled the selected index change =
on the dropdown </PRE><PRE>boolServersLoaded =3D =
True</PRE><PRE>slDBList.Text =3D ""</PRE><PRE>Catch ex As =
Exception</PRE><PRE>MessageBox.Show("Error loading server list. Error: " =
& ex.ToString, "Data Error", MessageBoxButtons.OK, =
MessageBoxIcon.Error)</PRE><PRE>boolServersLoaded =3D =
False</PRE><PRE>slDBList.Text =3D =
""</PRE><PRE>Finally</PRE><PRE>Me.Cursor =3D Cursors.Arrow</PRE><PRE>End =
Try</PRE></BODY></HTML>
------=_NextPart_000_0354_01C8BB3B.79B811B0--
Take a look at the BackgroundWorker component.
--
Tom Shelton
.
- References:
- Long Process
- From: John Wright
- Long Process
- Prev by Date: Re: Long Process
- Next by Date: Re: Long Process
- Previous by thread: Re: Long Process
- Next by thread: Re: Long Process
- Index(es):