C
Carsten Marx
Hello,
now i successfully added a BackgroundWorker to my App on a panel with:
BackgroundWorker bgWorker;
.....
.....
this.bgWorker = new BackgroundWorker();
this.bgWorker.DoWork +=new DoWorkEventHandler(bgWorker_DoWork);
this.bgWorker.ProgressChanged +=new
ProgressChangedEventHandler(bgWorker_ProgressChanged);
this.bgWorker.RunWorkerCompleted +=new
RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
this.bgWorker.WorkerReportsProgress = true;
this.bgWorker.WorkerSupportsCancellation = true;
.....
public void sieveIt(int position)
{
....// some computation
this.organizeTheSieveOrder();
this.cleanTheView(); // remove all "old" controls from the panel
this.Controls.Add(this.progressPanel); //add the status panel
this.bgWorker.RunWorkerAsync(this); // start the BackgroundWorker
}
.....
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
this.actualizeClustersSizes();
/* in actualizeClustersSizes there are opened a few database connections
to get data.. withuot touching the gui... in the method after each
connection there is an this.bgWorker.ReportProgress(v) where v is the
current percentage... */
}
private void bgWorker_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
this.progressLabel.Text = e.ProgressPercentage.ToString() + " %";
this.progressBar.Value = e.ProgressPercentage;
}
private void bgWorker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
this.progressBar.Value = 0;
this.Controls.Remove(this.progressPanel); // remove the progresspanel
this.refreshView(); // refresh the Panel and add the new controls
if(this.currentStep == 3) this.showTable(true);
this.bgWorker.CancelAsync(); // cancel the bgWorker
}
Moe my Problem is, that everything works fine for a while... but when i
work a little bit with the app, the app is freezing.... and it's not
repeatable... Why?
Another question: Is it possible to stop the BgWoker at my own (like:
bgWorker.Stop() ...)
Thanks for any help...
Regards
Carsten
now i successfully added a BackgroundWorker to my App on a panel with:
BackgroundWorker bgWorker;
.....
.....
this.bgWorker = new BackgroundWorker();
this.bgWorker.DoWork +=new DoWorkEventHandler(bgWorker_DoWork);
this.bgWorker.ProgressChanged +=new
ProgressChangedEventHandler(bgWorker_ProgressChanged);
this.bgWorker.RunWorkerCompleted +=new
RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
this.bgWorker.WorkerReportsProgress = true;
this.bgWorker.WorkerSupportsCancellation = true;
.....
public void sieveIt(int position)
{
....// some computation
this.organizeTheSieveOrder();
this.cleanTheView(); // remove all "old" controls from the panel
this.Controls.Add(this.progressPanel); //add the status panel
this.bgWorker.RunWorkerAsync(this); // start the BackgroundWorker
}
.....
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
this.actualizeClustersSizes();
/* in actualizeClustersSizes there are opened a few database connections
to get data.. withuot touching the gui... in the method after each
connection there is an this.bgWorker.ReportProgress(v) where v is the
current percentage... */
}
private void bgWorker_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
this.progressLabel.Text = e.ProgressPercentage.ToString() + " %";
this.progressBar.Value = e.ProgressPercentage;
}
private void bgWorker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
this.progressBar.Value = 0;
this.Controls.Remove(this.progressPanel); // remove the progresspanel
this.refreshView(); // refresh the Panel and add the new controls
if(this.currentStep == 3) this.showTable(true);
this.bgWorker.CancelAsync(); // cancel the bgWorker
}
Moe my Problem is, that everything works fine for a while... but when i
work a little bit with the app, the app is freezing.... and it's not
repeatable... Why?
Another question: Is it possible to stop the BgWoker at my own (like:
bgWorker.Stop() ...)
Thanks for any help...
Regards
Carsten