R
Rotsey
Hi,
Anyone able to look at this code with backgroundworker.
I am calling a FindDuplicates class and need to pass in
the DriveData class that is passed into the form.
So it is necessary to pass in to RunWorkerAsync the
DriveData object or can I just access it from the form
level variable.???
Also I am passing into the FindDuplicates a ref to the background worker
so it can report progress using the ReportProgress method,
is this the right way???
And thirdly the is passing the result of FindDuplicates to
RunWorkerCompleted correct??
Malcolm
public partial class frmDuplicates : Form
{
private DriveData mDriveData;
private BackgroundWorker mWorker;
public frmDuplicates(DriveData data)
{
mDriveData = data;
InitializeComponent();
mWorker = new BackgroundWorker();
mWorker.DoWork += new DoWorkEventHandler(mWorker_DoWork);
mWorker.WorkerReportsProgress = true;
mWorker.ProgressChanged += new
ProgressChangedEventHandler(mWorker_ProgressChanged);
mWorker.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(mWorker_RunWorkerCompleted);
mWorker.RunWorkerAsync(mDriveData);
}
void mWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs
e)
{
FileDuplicates dup = e.Result as FileDuplicates;
FileExplorer exp = new FileExplorer(dup.Files, mDriveData);
splitContainer1.Panel1.Controls.Add(exp);
}
void mWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.Text = e.ProgressPercentage.ToString("0%");
}
void mWorker_DoWork(object sender, DoWorkEventArgs e)
{
DriveData data = e.Argument as DriveData;
FileDuplicates dup = new FileDuplicates(data);
if (dup.FindDuplicates(mWorker))
{
e.Result = dup;
}
}
private void frmDuplicates_Load(object sender, EventArgs e)
{
}
}
Anyone able to look at this code with backgroundworker.
I am calling a FindDuplicates class and need to pass in
the DriveData class that is passed into the form.
So it is necessary to pass in to RunWorkerAsync the
DriveData object or can I just access it from the form
level variable.???
Also I am passing into the FindDuplicates a ref to the background worker
so it can report progress using the ReportProgress method,
is this the right way???
And thirdly the is passing the result of FindDuplicates to
RunWorkerCompleted correct??
Malcolm
public partial class frmDuplicates : Form
{
private DriveData mDriveData;
private BackgroundWorker mWorker;
public frmDuplicates(DriveData data)
{
mDriveData = data;
InitializeComponent();
mWorker = new BackgroundWorker();
mWorker.DoWork += new DoWorkEventHandler(mWorker_DoWork);
mWorker.WorkerReportsProgress = true;
mWorker.ProgressChanged += new
ProgressChangedEventHandler(mWorker_ProgressChanged);
mWorker.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(mWorker_RunWorkerCompleted);
mWorker.RunWorkerAsync(mDriveData);
}
void mWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs
e)
{
FileDuplicates dup = e.Result as FileDuplicates;
FileExplorer exp = new FileExplorer(dup.Files, mDriveData);
splitContainer1.Panel1.Controls.Add(exp);
}
void mWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.Text = e.ProgressPercentage.ToString("0%");
}
void mWorker_DoWork(object sender, DoWorkEventArgs e)
{
DriveData data = e.Argument as DriveData;
FileDuplicates dup = new FileDuplicates(data);
if (dup.FindDuplicates(mWorker))
{
e.Result = dup;
}
}
private void frmDuplicates_Load(object sender, EventArgs e)
{
}
}