Code Busy Message

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi,

I am looking for a more elegant solution to the wait cursor. There are
some places in the software I have created where there is a few seconds
lag where the DB processes requests and sends back the data.

Right now I have used the wait cursor, but I would like to popup a form
or something like that with a message and an animated image.

Does anyone have a solution or can you point me to one?

Thanks

Tim
 
Tim said:
Hi,

I am looking for a more elegant solution to the wait cursor. There are
some places in the software I have created where there is a few seconds
lag where the DB processes requests and sends back the data.

Right now I have used the wait cursor, but I would like to popup a form
or something like that with a message and an animated image.

Does anyone have a solution or can you point me to one?

Thanks

Tim
If you go to the following url:
http://www.vkarlsen.no/LVK.NET/releases/latest.html

download my library source and find the Threading folder (LVK.Threading
namespace) you'll find a ThreadProgressDialog class with a helper form.
It isn't the nicest form available, got some colorization problems in XP
with themes but it does the job. It'll run in its own thread, can
provide a simple animation, show a progress bar with estimated time
left, etc. The form is controlled through the ThreadProgressDialog
object and is thread-safe so you can safely modify properties on the
form through it. Here's a simple example:

using (ThreadProgressDialog dlg = new ThreadProgressDialog())
{
dlg.ShowTimeLeft = true;
dlg.ShowProgressBar = true;
dlg.AllowAbort = false;
dlg.MinimumValue = 0;
dlg.MaximumValue = 100;
dlg.Title = "Lengthy process";
dlg.Text = "Please wait, wasting your time...";
dlg.Show();

for (Int32 index = 0; index <= 100; index++)
{
System.Threading.Thread.Sleep(100);
dlg.CurrentValue = index;
}
}

There's a bug apparently when using the abort button so I need to fix
that sometime.

Also, if you show the form, does some setup, and then start moving the
progressbar, it'll estimate the end time incorrectly because it uses the
time from the form was shown. If you want to "fix" this, call the
..ResetStartTime() method to reset the time it uses to calculate the end
time from.
 
Lasse said:
If you go to the following url:
http://www.vkarlsen.no/LVK.NET/releases/latest.html

download my library source and find the Threading folder (LVK.Threading
namespace) you'll find a ThreadProgressDialog class with a helper form.
There's a bug apparently when using the abort button so I need to fix
that sometime.
<snip>

The bug with Abort was in the form, the event handler was for some
reason no longer linked to the button Click event. If you fix that, the
modified example is as follows:

using (ThreadProgressDialog dlg = new ThreadProgressDialog())
{
dlg.ShowTimeLeft = true;
dlg.ShowProgressBar = true;
dlg.AllowAbort = true;
dlg.MinimumValue = 0;
dlg.MaximumValue = 100;
dlg.Title = "Lengthy process";
dlg.Text = "Please wait, wasting your time...";
dlg.Show();
dlg.ResetStartTime();

for (Int32 index = 0; index <= 100; index++)
{
System.Threading.Thread.Sleep(100);
dlg.CurrentValue = index;

if (dlg.CheckAbort())
{
dlg.Dispose(); // need to do this to get rid of the form
MessageBox.Show("Aborted by user");
break;
}
}
}
 
Back
Top