Passing Custom Object to Progress Changed method. C# -


i stages of c# venture apologise if simple question. have looked , looked on line answer can't find anything.

basically trying pass custom object progress changed method background worker thread can update few labels , rich text box. know report progress method can pass int , object. when do, doesn't let me access in bw_progresschanged method.

here snippets of code --

bacgkround worker

private void bw_dowork(object sender, doworkeventargs e) {      backgroundworker worker = sender backgroundworker;      userstatesettings user = new userstatesettings();       user.rtbtext = "text";       worker.reportprogress(0, user);                  if ((worker.cancellationpending == true))      {          e.cancel = true;       }      else      { .....}  } 

userstatesettings class

 public class userstatesettings  {       string _rtbtext;       int _productsprocessed;        public string rtbtext       {                     {             return _rtbtext;           }           set           {             _rtbtext = value;           }       } 

bw_progresschanged (i trying objects property rtbtext richtext box here, wont let me.)

 private void bw_progresschanged(object sender, progresschangedeventargs e)  {      this.richtextbox1.text = ....       this.refresh();  } 

hopefully makes sense, if shed light appreciate !

you should able pull object e.userstate property. need cast type use it.

user user = e.userstate user; if (user != null) {    // populate ui fields } 

see https://msdn.microsoft.com/en-us/library/system.componentmodel.progresschangedeventargs.userstate(v=vs.110).aspx


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -