首页 > 代码库 > 线程启动带参数

线程启动带参数

public void StartThread()         {            Thread TempThread = new Thread(new ThreadStart(Start));            TempThread.Start();        }

带参数的:

public void StartThread()         {            Thread TempThread = new Thread(new ParameterizedThreadStart(Start));            TempThread.Start();        }        public void Start(object ip)         {            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);            bool isGo = true;            server.Bind(new IPEndPoint(IPAddress.Parse(ip.ToString()), 3001));            server.Listen(10);            while (isGo)             {                try                {                    Socket s = server.Accept();                    string content = "";                    byte[] bytes = new byte[s.Available];                    int num = s.Receive(bytes, 0, bytes.Length, SocketFlags.None);                    content = Encoding.ASCII.GetString(bytes);                    if (content.Equals("conn"))                     {                        s.Send(Encoding.ASCII.GetBytes("connstr"));                    }                    if (content.Equals("Close"))                     {                        isGo = false;                    }                    s.Close();                    s.Dispose();                }                catch (Exception ex)                {                                    }            }            server.Close();            server.Dispose();        }