N
nick_nw
Hi,
I'm creating a progress form. The form contains a progress bar, but
with marquee style enabled (.Net 1.1, so this is achieved via calls to
user32.dll methods).
My form has a static method that looks something like this:
public static void Show (ProgressFormWorkDelegate workMethod)
{
ProgressForm pForm = new ProgressForm ();
Thread workThread = null;
pForm.workMethod = workMethod;
if (pForm.workMethod != null)
{
workThread = new Thread (new ThreadStart
(pForm.ProgressFormWork));
workThread.Name = "ProgressForm.ProgressFormWork";
workThread.Start ();
}
pForm.ShowDialog ();
}
private void ProgressFormWork ()
{
// Execute the client's work package in this thread.
workMethod ();
// What to do here? I could enable a close button, but sometimes I
want this form to close of its own accord so that Show will return to
the caller.
}
Now I could call this.Close from the workThread method to achieve what
I want, but I worry that I'm introducing a race condition (that the
form might not have finsihed showing by this stage). Am I worrying
uneccessarily? Is there a better way to do this?
I'm creating a progress form. The form contains a progress bar, but
with marquee style enabled (.Net 1.1, so this is achieved via calls to
user32.dll methods).
My form has a static method that looks something like this:
public static void Show (ProgressFormWorkDelegate workMethod)
{
ProgressForm pForm = new ProgressForm ();
Thread workThread = null;
pForm.workMethod = workMethod;
if (pForm.workMethod != null)
{
workThread = new Thread (new ThreadStart
(pForm.ProgressFormWork));
workThread.Name = "ProgressForm.ProgressFormWork";
workThread.Start ();
}
pForm.ShowDialog ();
}
private void ProgressFormWork ()
{
// Execute the client's work package in this thread.
workMethod ();
// What to do here? I could enable a close button, but sometimes I
want this form to close of its own accord so that Show will return to
the caller.
}
Now I could call this.Close from the workThread method to achieve what
I want, but I worry that I'm introducing a race condition (that the
form might not have finsihed showing by this stage). Am I worrying
uneccessarily? Is there a better way to do this?