M
martin
I'm trying to display a progress bar while some background processing
is done in my PPC app. I am using Control.Invoke, but it's not
working quite right. Here's a code snippet:
private void Start()
{
this.mLoading = true;
Thread loadingThread = new Thread(new ThreadStart(AnimateProgressBar));
loadingThread.Start();
/* some long running processes */
this.mLoading = false;
}
private void AnimateProgressBar()
{
while (this.mLoading)
{
this.mLoadingProgressBar.Invoke(new EventHandler(this.SetProgressBar));
// i've experimented with Thread.Sleep()
// Thread.Sleep(1000);
}
}
private void SetProgressBar(object sender, EventArgs e)
{
if (this.mLoadingProgressBar.Value < (this.mLoadingProgressBar.Maximum - 10))
this.mLoadingProgressBar.Value += 10;
else
this.mLoadingProgressBar.Value = 0;
}
The first time I execute this code, the SetProgressBar method gets
called one time, and the control is never repainted to reflect the new
value. If I invoke the Start method again, SetProgressBar never gets
called, and the application hangs.
Does anyone have any idea why this particular code might not be
working correctly? Or does anyone have any suggestions on a better
way to accomplish what I'm trying to do?
Thanks in advance.
Martin
is done in my PPC app. I am using Control.Invoke, but it's not
working quite right. Here's a code snippet:
private void Start()
{
this.mLoading = true;
Thread loadingThread = new Thread(new ThreadStart(AnimateProgressBar));
loadingThread.Start();
/* some long running processes */
this.mLoading = false;
}
private void AnimateProgressBar()
{
while (this.mLoading)
{
this.mLoadingProgressBar.Invoke(new EventHandler(this.SetProgressBar));
// i've experimented with Thread.Sleep()
// Thread.Sleep(1000);
}
}
private void SetProgressBar(object sender, EventArgs e)
{
if (this.mLoadingProgressBar.Value < (this.mLoadingProgressBar.Maximum - 10))
this.mLoadingProgressBar.Value += 10;
else
this.mLoadingProgressBar.Value = 0;
}
The first time I execute this code, the SetProgressBar method gets
called one time, and the control is never repainted to reflect the new
value. If I invoke the Start method again, SetProgressBar never gets
called, and the application hangs.
Does anyone have any idea why this particular code might not be
working correctly? Or does anyone have any suggestions on a better
way to accomplish what I'm trying to do?
Thanks in advance.
Martin