c# 多线程委托传参方式

时间:2021-03-22 21:24:05

 

1.定义一个线程调用的方法函数

private void RTPServer(object _Serverip)
{
IPEndPoint Serverip = _Serverip as IPEndPoint;

}

2.Thread _ReceiveThread ;//创建一个线程实例

3.调用函数

private void button4_Click(object sender, EventArgs e)
{
IPAddress ipaddress = IPAddress.Parse(txtIP.Text);
IPEndPoint ip = new IPEndPoint(ipaddress, 12006);

_ReceiveThread = new Thread(new ThreadStart(delegate { RTPServer(ip); }));
_ReceiveThread.IsBackground = true;
_ReceiveThread.Priority = ThreadPriority.AboveNormal;
_ReceiveThread.Start();

}