c# - Cross-thread operation not valid control -


I know there are a lot of tips about my question but I have not found solutions for my case ... < / P>

I have a panel which I add control over the runtime, I tried this code but it does not help me, and says an error:

Cross- Thread operation is not valid

Here my code:

  Public Zero AddControlToPanel (panel panel, control ctrl In addition to the thread was less addressed Control accessed from a thread 1 'Panel') {If (panel.InvokeRequired) {panel.Invoke ((MethodInvoker) representative {AddControlToPanel (panel, ctrl);}); Return; } And panel. Control. Add (ctrl); }  

And I call it like this:

  AddControlToPanel (panel1, ctrl); You can create a control extension within the namespace of your project like this:  

and use it within your code like this:

  this.UIThread ((=) => (panel1.Controls. Add (Ctrl);});  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -