多线程,
示例:
using System.Threading;
private Socket socket;
//启动线程(可以放在接受按钮事件中);
thread1 = new Thread(new ThreadStart(Revice));
thread2.Start();
//接受信息方法
private string recvStr = "";
private void Revice()
{
while (true)
{
try
{
if (socket.Available != 0)
{
byte[] buffer = new byte[1024];
int length = socket.Receive(buffer);
recvStr =Encoding.Default.GetString(buffer, 0, length);
}
}
}
catch (Exception)
{
}
finally { }
}
}