winforms - C#, background worker class -


when compile code error, object reference set null, , error location in dowork, argumenttest.valueone = 8;

public partial class form1 : form {     backgroundworker bgw1 = new backgroundworker();     public form1()     {         initializecomponent();         // bgw1.runworkerasync(test1);          test test1 = new test         {             valueone = 5,             valuetwo = 10         };         bgw1.runworkerasync(test1);     }      class test     {          public int valueone { get; set; }         public int valuetwo { get; set; }     }      private void bgw1_dowork(object sender, doworkeventargs e)     {         test argumenttest = e.argument test;         thread.sleep(10);          argumenttest.valueone = 8;         argumenttest.valuetwo = 10;          e.result = argumenttest;     }      private void bgw1_runworkercompleted(object sender, runworkercompletedeventargs e)     {         test test12 = e.result test;         button1.text = test12.valueone.tostring();// +test.valuetwo.tostring();         //this.text = test.valueone.tostring() + " "+ test.valuetwo.tostring();     }      private void button1_click(object sender, eventargs e)     {          bgw1.dowork += bgw1_dowork;         bgw1.runworkercompleted += bgw1_runworkercompleted;         //bgw1.runworkerasync(test);      } } 

there 2 possible ways argumenttest ends null:

  1. argumenttest sent null runworkerasync.

  2. e.argument test; e.argument not compliant test, , as operator makes null.

it hard see one, since code example above quite messed up.

edit

can confirm code exactly decyclone edited it? in case, looks fine, , should have worked far can see.

set breakpoint on first line of dowork method, , when debugging should able see if 1. or 2. problem hovering on e.argument .


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -