Home > Net >  Who teach foreach
Who teach foreach

Time:01-07

I now is added in the foreach entrusted to generate controls, foreach is used to receive information from the network of equipment, the result can't get a device with a delegate pass information

CodePudding user response:

If it is directly in the foreach loop will generate a panel directly to quote on a thread to create controls can't be in another thread is created on the control of the parent

CodePudding user response:

Out of memory?

CodePudding user response:

refer to the second floor icoolno1 response:
memory?
I just started to learn this before contact with the now I mainly want to directly in the foreach loop to generate a panel but he will directly report cannot be created on a thread control on another thread to create the control of the parent, head

CodePudding user response:

You write directly in the cycle must be the child thread cannot access the UI thread control,
You write in the commissioned, of course I can, but you can use anonymous functions, the body of the function to write directly in the foreach, such as:
 int a=0; 
Enclosing the Invoke (delegate ()
{
A=1;
Console. WriteLine (a);
});


Only need to pay attention to resolving the variable scope closure promotion problems,

CodePudding user response:

reference 4 floor morning to evening reply:
you write directly in the cycle must be the child thread cannot access the UI thread control,
You write in the commissioned, of course I can, but you can use anonymous functions, the body of the function to write directly in the foreach, such as:
 int a=0; 
Enclosing the Invoke (delegate ()
{
A=1;
Console. WriteLine (a);
});


Only need to pay attention to resolving the variable scope closure promotion problems,
, I'm a little don't understand your meaning, I mean I can use in the foreach K3Infos. Key. The value, to get what I want, I can also get on Form interface (premise is pulled in the interface rather than the code loop), but I used to entrust cycle to generate control word is can't get the, I'm going to the value of no value in debugging information, the foreach is continually receiving device transmits information through K3Infos. Then the Key. The value for value,

CodePudding user response:

reference 4 floor morning to evening reply:
you write directly in the cycle must be the child thread cannot access the UI thread control,
You write in the commissioned, of course I can, but you can use anonymous functions, the body of the function to write directly in the foreach, such as:
 int a=0; 
Enclosing the Invoke (delegate ()
{
A=1;
Console. WriteLine (a);
});


Only need to pay attention to resolving the variable scope closure promotion problems,
I will call in the Form1Load jieshou this thread, so as to achieve the purpose of receiving equipment information, that is because it has to entrust the way to create a thread in the foreach, otherwise will be reported in a thread cannot be created on a control on another thread to create the control of the parent
  • Related