views:

510

answers:

2

This is the setup I have, this code works properly

private void butGo_Click(object sender, EventArgs e)
{
  threadCreateImages.RunWorkerAsync();
}


private void threadCreateImages_DoWork(object sender, DoWorkEventArgs e)
{
  PatientToHL7MSHManager tvPatientToHL7MSHManager = new PatientToHL7MSHManager();
  tvPatientToHL7MSHManager.LoadByMSHID(""); 
}


private void threadCreateImages_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
  MessageBox.Show("DONE"); 
}

if I change this line tvPatientToHL7MSHManager.LoadByMSHID(""); to tvPatientToHL7MSHManager.LoadByPatientID("");

It skips over the DoWork event and goes straight to the RunWorkerCompleted event.

The only difference between the LoadByMSHID and the LoadByPatientID is the filter on the SQL statement besides that the code path is identical.

The code does work properly without the background thread.

Any ideas or suggestions would be very appreciated.

+7  A: 

Likely there's an exception being thrown. Within your RunWorkerCompleted event, check the Error property of the RunWorkerCompletedEventArgs value being passed in.

BackgroundWorkers do not raise exceptions up to the main thread when they occur. Instead, you have to check for them on the RunWorkerCompleted event.

Ray Vernagus
A: 

I'm not sure what the problem was but this resolved the issue.

Initialy I had just copied the business.dll into the bin folder and referenced it, however the folder contained an older business.obj file. When I copied both the business.dll and business.obj file the issue went away.