Don't know where to find this know, I don't think the like lambda expressions.
Private void button1_Click (object sender, EventArgs e)
{
If (this. For. Text=="connection")
{
//instantiate the socket
TcpClient=new Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp);
//IP4, byte streams, TCP
The EndPoint EP=new IPEndPoint (IPAddress. Parse (this) txt_IP) Text), int. J Parse (this) txt_Port) Text));
Try
{
TcpClient. Connect (EP);
}
The catch (Exception ex)
{
MessageBox. Show (" connection: "+ ex. Message);
return;
}
MessageBox. Show (" connection success ");
This. For. Text="close";
Task. Run (new Action (()=& gt; {GetPLCValue (); }));////is it????????????????????
}
The else
{
TcpClient? The Close ();
This. For. Text="connection";
}
}
CodePudding user response:
This is called commissioned sighCodePudding user response:
Task. Run: an asynchronous tasks (i.e. in another thread execution, does not affect the current code to continue)New Action: asynchronous tasks defined in this entrust
()=& gt; {... } : anonymous functions, namely internal name automatically by the system function, scope limited to the function body
Comprehensive, is an asynchronous tasks, task content is to perform a piece of code, the code content is: GetPLCValue ();
This statement some repetitive, which of the following is simplified as a result, the equivalent with the original statement:
Task. Run (()=& gt; {GetPLCValue (); });
CodePudding user response:
It is worse than one pace reachs the designated position: Task. Run (GetPLCValue);CodePudding user response:
Task. Run (new Action (()=& gt; {GetPLCValue (); }));////is it????????????????????-- -- -- -- -- -- -- -- -- -- --
This sentence to write many, should be this: new Action can omit
Task. Run (()=& gt; {GetPLCValue (); });
Is to open a thread, running GetPLCValue () method
()=& gt; {}
Is a function with no parameters of anonymous
CodePudding user response:
Asynchronous run an Action,