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.