线程调用带参数的函数..求助
就是新建一个调用带参数的函数的线程,并把参数传递给函数 老是出问题
private void RecThread(Socket client) { Thread Rec = new Thread(new ThreadStart(this.Receive)); Rec.Start(client); } private void Receive(Socket client) { . . . }
static void Main(string[] args) { SendMessage sm = new SendMessage(c); Thread sendThread = new Thread(new ThreadStart(sm.sendMessage)); sendThread.Start(); } public class SendMessage { private Socket s; public SendMessage(Socket param_socket) { this.s = param_socket; } public void sendMessage() { while(true) { string content = Console.ReadLine(); if (content == "Close") { Console.WriteLine("You have AFK!"); break; } else { byte[] sendBytes = Encoding.ASCII.GetBytes(content); s.Send(sendBytes, sendBytes.Length, 0); } } } }