Reputation: 1429
dI have a winforms system tray application, that is monitoring job status via a database. I click on the system tray, and a menu of currently active jobs opens, and if I click on a job, I create a form which is supposed to show messages and a progress bar.
The form's constructor is
public JobStatusForm()
{
InitializeComponent();
activeJobsBGWorker = new BackgroundWorker();
activeJobsBGWorker.DoWork += new DoWorkEventHandler(activeJobsBGWorker_DoWork);
activeJobsBGWorker.ProgressChanged += new ProgressChangedEventHandler(activeJobsBGWorker_ProgressChanged);
activeJobsBGWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(activeJobsBGWorker_RunWorkerCompleted);
}
Then, the click event handler for the context method calls JobStatusForm.Show(). In the form, I have:
private void JobStatusForm_Shown(object sender, EventArgs e)
{
activeJobsBGWorker.RunWorkerAsync();
}
To start the worker.
I find that the worker starts, and then something raises the RunWorkerCompleted event. The sender is a background worker, and the event args are null.
How can I find out what is raising this event , and how can I make it stop/restart?
Thanks,
EDIT:
currently, the Do_Work code looks like this:
private void activeJobsBGWorker_DoWork(object sender, DoWorkEventArgs e)
{
//while (!e.Cancel)
while (true)
{
_clr.JobStatus status = _clr.SystemDataHelper.GetCurrentJobActivity(_clr.SystemDataHelper.GetLocation(), this.job_ID);
//if (activeJobsBGWorker.CancellationPending)
// continue;
activeJobsBGWorker.ReportProgress(status.pc, status);
Thread.Sleep(250);
}
}
I have set a breakpoint on the ReportProgress line, and it is never hit.
The call into _clr is to a C++ project built as a dll, and calls a static method which calls the database.
Upvotes: 0
Views: 1932
Reputation: 1429
Exceptions in the Do_Work method also cause RunWorkerCompleted to be fired.
Upvotes: 3