c# - Invoke Property -


i have written program in synchronous model want add threading long tasks, have several properties automate retrieval of information like:

private int tabidx { { return tabs.selectedindex; } }  private string tabname { { return tabs.selectedtab.text; } }  public tabcontrols tabcontrols { { return (tabcontrols)tabs.tabpages[tabidx].controls[string.format("tab_{0}_controls", tabidx)]; } } internal tabcontrols gettabcontrols(string name) {     int desiredidx = tabs.tabpages.indexofkey(name);     return (tabcontrols)tabs.tabpages[desiredidx].controls[string.format("tab_{0}_controls", desiredidx)]; }  public core rcore { { return rdbcores[tabidx]; } } 

obviously if try access these properties inside task.run(()) or likewise i'm going cross-thread exception.

so question is:

is possible invoke these properties method similar too:

private void invokeifrequired(isynchronizeinvoke obj, methodinvoker action) {     if (obj.invokerequired) { obj.invoke(action, new object[0]); }     else { action(); } } 

in general, use following invoke properties different tasks. can't follow code, wehre want invoke, have adjust code application needs:

button1.invoke(new action(()=>button1.visible = true;)) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -