x***@y.com
2018-12-29 19:04:07 UTC
I have a long running operation running on the UI thread.
I want to show a progress bar while this operation is running.
The basic structure I have is below.
I want the timer event and update of the progress bar to happen on a
different thread or task while the long operation is running.
I should also mention that the long running operation also updates
other parts of the UI as it runs.
Can this be done?
private void btnStart_Click(object sender, EventArgs e)
{
StartProgressBar();
// start long running operation
StopProgressBar();
}
private void StartProgressBar()
{
tmrProgress.Enabled = true;
}
private void StopProgressBar()
{
tmrProgress.Enabled = false;
}
private void tmrProgress_Tick(object sender, EventArgs e)
{
if ((progressBar1.Value + 10) > progressBar1.Maximum)
{
progressBar1.Value = progressBar1.Minimum;
}
else
{
progressBar1.Value += 10;
}
}
I want to show a progress bar while this operation is running.
The basic structure I have is below.
I want the timer event and update of the progress bar to happen on a
different thread or task while the long operation is running.
I should also mention that the long running operation also updates
other parts of the UI as it runs.
Can this be done?
private void btnStart_Click(object sender, EventArgs e)
{
StartProgressBar();
// start long running operation
StopProgressBar();
}
private void StartProgressBar()
{
tmrProgress.Enabled = true;
}
private void StopProgressBar()
{
tmrProgress.Enabled = false;
}
private void tmrProgress_Tick(object sender, EventArgs e)
{
if ((progressBar1.Value + 10) > progressBar1.Maximum)
{
progressBar1.Value = progressBar1.Minimum;
}
else
{
progressBar1.Value += 10;
}
}