I have a very strange problem with a background worker in one of my applications. I recently revised it a bit with some GUI fixes, but now when someone on another PC launches .exe or installs my OneClick deployment, the background worker is not in the dowork event. The logic has not changed between the two versions. I made a comparison and, in addition, adding more errors, nothing has changed.
I got to the inclusion of message boxes and breakpoints in the dowork event, but it never gets into it anywhere except my own computer. Even when remote debugging is not included in the DoWork event
Any suggestions?
The click button even triggers the runworkerasync event
private void ScanButton_Click_1(object sender, RoutedEventArgs e) { Scan = new BackgroundWorker(); Scan.WorkerReportsProgress = true; Scan.DoWork += new DoWorkEventHandler(Scan_DoWork); Scan.ProgressChanged += new ProgressChangedEventHandler(Scan_ProgressChanged); Scan.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Scan_RunWorkerCompleted); Scan.RunWorkerAsync(); }
Below is the code that fires the DoWork event. Ive removed the other functions that it does for simplicity. All he does is run a function that returns a string and puts it in a list called scanresults.
private BackgroundWorker Scan; public void Scan_DoWork(object sender, DoWorkEventArgs e) { System.Windows.Forms.MessageBox.Show("Inside the DoWork"); BackgroundWorker bw = sender as BackgroundWorker; float percentageDone = 0.0F; ScanResults = new List<string>(); try { System.Windows.Forms.MessageBox.Show("Doing first scan check"); ScanResults.Add(Functions.LocalComputerName()); percentageDone = ((1 / 1f) * 100f); bw.ReportProgress((int)percentageDone); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } public void Scan_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { if (ScanResults.Count == 0) { System.Windows.Forms.MessageBox.Show("Empty"); return; } MachineNameBox.Text = ScanResults[0]; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
It completely ignores the dowork event and enters the runworkercomplete event and passes an error for the index, obviously because the list was not populated because the function was skipped. Again, this works fine on my PC, but not on others, no matter how I release them.
Thanks for any help