I create a backgroundworker process in the form..
BackgroundWorker bw = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
Also, i have a progress bar control inside the form(progress bar minimum and maximum values are 1 and 100).
In my button click,
where the click event will fire the actual method calls which are supposed to run in the background and in parallel, start showing the progress bar steps....
if (bw.IsBusy)
{
return;
}
bw.DoWork += (bwSender, bwArg) =>
{
MethodCall1(); - Does some database insertions..
MethodCall2(); - Does some database select...
}
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += (bwSender, bwArg) =>
{
bw.Dispose();
};
bw.RunWorkerAsync();
For progress bar to show the progressing...
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
The issue i face is, progress bar is not stepping, it stands still and there is no progress bar's progress.
I also tried inserting bw.ReportProgress(integervalue) in my actual methods, but, it didn't help.
How can i have a backgroundworker thread handling method calls and in parallel display the progress of progress bar, after the method calls are done, i want to end the progress bar step.
object.event += () => {}
is considered leaky. A good way is to declare variable first:var handler = () => {}
. Thenobject.event += handler;
and laterobject.event -= handler;
– T.S.