C
c-sharp newbie!
Dear all,
I have a form which temporarily creates another form and has a
progressbar on it. I got trouble with updating the screen, if I didn't
use a background-worker. Therefore: My code looks something like the
following:
public partial class newForm : Form
{
public newForm()
{
InitializeComponent();
//this.Show();
//this.Activate();
this.progressBar1.Step = 1;
this.progressBar1.Maximum = 100;
BackgroundWorker bw0 = new BackgroundWorker();
bw0.WorkerReportsProgress = true;
bw0.DoWork += delegate(object sender0, DoWorkEventArgs e0)
{
for (int i = 0; i < 15; i++)
{
System.Threading.Thread.Sleep(50);
bw0.ReportProgress(i);
}
};
bw0.ProgressChanged += delegate(object sender0,
ProgressChangedEventArgs e0)
{
this.progress_indicator.Text = string.Format("{0}%",
e0.ProgressPercentage);
this.progressBar1.PerformStep();
};
bw0.RunWorkerCompleted += delegate(object sender0,
RunWorkerCompletedEventArgs e0)
{
// Here I insert 6 extra background-workers after
the previous completed - this is wrong!
}
Okay: My problem is that when I put code inside
bwXXXX.RunWorkerCompleted, everything works - except that I cannot
continue to update by using my bwXXXXX.ReportProgress(i). Therefore I
have some really really ugly code with many layers of background-
workers...
In addition, I need to get something like: (int)this.Handle
I cannot seem to be able to get: (int)this.Handle inside any of my
bwXXXXX.DoWork'ers.... Instead of having all my background-workers, I
only need a single one and put my code inside the bw0.DoWork (my code
is 100% sequential).
Any hints on why this doesn't work - do I need to post more code? I
hope this is sufficient for a qualified answer...
I have a form which temporarily creates another form and has a
progressbar on it. I got trouble with updating the screen, if I didn't
use a background-worker. Therefore: My code looks something like the
following:
public partial class newForm : Form
{
public newForm()
{
InitializeComponent();
//this.Show();
//this.Activate();
this.progressBar1.Step = 1;
this.progressBar1.Maximum = 100;
BackgroundWorker bw0 = new BackgroundWorker();
bw0.WorkerReportsProgress = true;
bw0.DoWork += delegate(object sender0, DoWorkEventArgs e0)
{
for (int i = 0; i < 15; i++)
{
System.Threading.Thread.Sleep(50);
bw0.ReportProgress(i);
}
};
bw0.ProgressChanged += delegate(object sender0,
ProgressChangedEventArgs e0)
{
this.progress_indicator.Text = string.Format("{0}%",
e0.ProgressPercentage);
this.progressBar1.PerformStep();
};
bw0.RunWorkerCompleted += delegate(object sender0,
RunWorkerCompletedEventArgs e0)
{
// Here I insert 6 extra background-workers after
the previous completed - this is wrong!
}
Okay: My problem is that when I put code inside
bwXXXX.RunWorkerCompleted, everything works - except that I cannot
continue to update by using my bwXXXXX.ReportProgress(i). Therefore I
have some really really ugly code with many layers of background-
workers...
In addition, I need to get something like: (int)this.Handle
I cannot seem to be able to get: (int)this.Handle inside any of my
bwXXXXX.DoWork'ers.... Instead of having all my background-workers, I
only need a single one and put my code inside the bw0.DoWork (my code
is 100% sequential).
Any hints on why this doesn't work - do I need to post more code? I
hope this is sufficient for a qualified answer...