c# winform socket关闭时需要关闭的东西,停止服务,停止监听,停止socket

1,线程需要关闭
Thread TempThread;
//开启接收线程
TempThread = new Thread(new ThreadStart(this.StartReceive));
TempThread.IsBackground = true;//设置为后台线程
TempThread.Start();

TempThread.Abort();//关闭线程


2,监听需要关闭
TcpListener lisner;
//创建网络监听
lisner = new TcpListener(ipep);
lisner.Start();

lisner.Stop();


3,Socket需要关闭
Socket client = lisner.AcceptSocket();

//关闭套接字
client.Close();


4,如果是传文件的话还需要关闭流文件
FileStream MyFileStream = new FileStream(fileFullName, FileMode.Create, FileAccess.Write);

//关闭文件流
MyFileStream.Close();


黑色头发:http://heisetoufa.iteye.com
展开阅读全文

没有更多推荐了,返回首页