0

When I call to the ProgressChanged method I'm getting an InvalidOperationException I found out on MSDN that this happens because the WorkerReportsProgress is set to false but it is set to true in my program.

This is the BW initializations:

        bw = new BackgroundWorker();
        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
        bw.WorkerReportsProgress = true;
        bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

The call to the Progress:

   tempNetwork.Nodes.Add(tempNode);
   bw.ReportProgress(1, tempNetwork);

tempNetwork is local

Yogevnn
  • 1,430
  • 2
  • 18
  • 37
  • More information/code needed to analyze the problem. – Sani Huttunen May 10 '14 at 22:55
  • What is `tempNetwork`, what `tempNode`? Are you creating GUI elements in bgw? – JeffRSon May 10 '14 at 23:06
  • @JeffRSon not binded UI elements, they are model elemnets that i'm adding to the Main UI element (`Network`) on the main thread (in the `progressChanged`) – Yogevnn May 10 '14 at 23:27
  • 1
    GUI elements must not be created in a non-GUI thread. Where you actually add those is irrelevant. – JeffRSon May 11 '14 at 07:10
  • I'm creating a temp Model element and then passing it to the `progressChanged` to be added to the binded UI element – Yogevnn May 11 '14 at 13:41
  • InvalidOperationException has more than one cause. WPF is very picky about where you create objects. The exception details would show the cause, you should never omit the message and the stack trace from a question. – Hans Passant May 12 '14 at 12:54

0 Answers0