30secondstosam
Programmer
Hi all,
I'm new to C# so please bare with me on this one...
I'm having a bit of trouble making the background worker do it's stuff...
Code:
int chkd = 0;
int total = 0;
private void resize_all()
{
ImageProcessor ip = new ImageProcessor();
int chkd = (this.cbThbNail.Checked ? 1 : 0);
chkd+= (this.cbQXGA.Checked ? 1 : 0);
chkd+= (this.cbSVGA.Checked ? 1 : 0);
chkd+= (this.cbUXGA.Checked ? 1 : 0);
chkd+= (this.cbVGA.Checked ? 1 : 0);
chkd+= (this.cbXGA.Checked ? 1 : 0);
ip.total = this.listBox1.Items.Count * chkd;
// thumbnails
if (this.cbThbNail.Checked)
{
resize_eachsize(ip, 75, 75);
}
}
private void resize_eachsize(ImageProcessor ip, int imgHeight, int imgWidth)
{
foreach (string img in this.listBox1.Items)
{
ip.imageResize(imgHeight, imgWidth, img, this.dirFinBox.Text);
backgroundWorker1.ReportProgress((int)(ip.done / ip.total) * 100);
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
backgroundWorker1.ReportProgress(0);
resize_all();
backgroundWorker1.ReportProgress(100);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar.Value=e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// re-enables form - shows process as complete
MessageBox.Show("Process Complete!");
this.progressBar.Value = 0;
this.Enabled = true;
}
---------
I know I'm probably doing something blindingly obvious but could someone please give me a nudge in the right direction?
Many thanks for your help!
I'm new to C# so please bare with me on this one...
I'm having a bit of trouble making the background worker do it's stuff...
Code:
int chkd = 0;
int total = 0;
private void resize_all()
{
ImageProcessor ip = new ImageProcessor();
int chkd = (this.cbThbNail.Checked ? 1 : 0);
chkd+= (this.cbQXGA.Checked ? 1 : 0);
chkd+= (this.cbSVGA.Checked ? 1 : 0);
chkd+= (this.cbUXGA.Checked ? 1 : 0);
chkd+= (this.cbVGA.Checked ? 1 : 0);
chkd+= (this.cbXGA.Checked ? 1 : 0);
ip.total = this.listBox1.Items.Count * chkd;
// thumbnails
if (this.cbThbNail.Checked)
{
resize_eachsize(ip, 75, 75);
}
}
private void resize_eachsize(ImageProcessor ip, int imgHeight, int imgWidth)
{
foreach (string img in this.listBox1.Items)
{
ip.imageResize(imgHeight, imgWidth, img, this.dirFinBox.Text);
backgroundWorker1.ReportProgress((int)(ip.done / ip.total) * 100);
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
backgroundWorker1.ReportProgress(0);
resize_all();
backgroundWorker1.ReportProgress(100);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar.Value=e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// re-enables form - shows process as complete
MessageBox.Show("Process Complete!");
this.progressBar.Value = 0;
this.Enabled = true;
}
---------
I know I'm probably doing something blindingly obvious but could someone please give me a nudge in the right direction?
Many thanks for your help!