c# - ILArrays as input arguments to BeginInvoke delegate -


in application, have background thread performs calculations , pushes resultant ilnumerics arrays view. having issues ilnumerics arrays getting disposed off when trigger view update function control.begininvoke.

are there specific function rules follow when passsing ilarrays input arguments begininvoke delegate?

here sample code.

void imainview.updatespectrumdata(ilinarray<float> wfmdata)         {             if (invokerequired)                 {                     begininvoke(new methodinvoker(() => addwfmtoview(wfmdata)), new object[] { wfmdata });                 }                 else                 {                     addwfmtoview(wfmdata);                 }             }         }          void addwfmtoview(ilinarray<float> wfmdata)         {            using(ilscope.enter(wfmdata))               {                  // update panel               }          } 

the problem compiler create anonymous class behind scenes. needed capture variables used in lambda expression. , class compiler not follow ilnumerics function rules. why see premature disposals.

the answer question is: ilarray not supported in lambda expressions. use care , if aware of subtleties related it.

in case, can work around problem falling ilnumerics.ilarray class usage. declare attribute in container class (form/control?) holds data used updating. updating routine can access attribute normally. common scenarios not need synchronization. (but always: think , make conscious decision!)

// local attribute 'transport' data ilarray<float> m_data = ilmath.localmember<float>();  public void updateview(ilinarray<float> wfmdata) {     using (ilscope.enter(wfmdata)) {         m_data.a = wfmdata;         addwfmtoview();      } } // actual update method not expose ilarray parameters. hence can use in lambda expression. void addwfmtoview() {     if (invokerequired) {         invoke(new methodinvoker(() => addwfmtoview()));     } else {         // access control here if necessary         panel.scene.first<illineplot>().update(m_data);         panel.configure();           panel.refresh();      }  } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -