首页 > 代码库 > 线程启动带参数
线程启动带参数
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(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。