110,535
社区成员
发帖
与我相关
我的任务
分享
Timer timer = new Timer();
//bool running = true; //是否仍需运行
private void recv()
{
while(running)
{
string s = 接收到的信息;
if(!s.StartWith("c2")) //假定c2是响应代码
{
timer.Enable = false;
}
}
}
private void deamo ()
{
while(running)
{
send("c1");//假定c1是控制代码
timer.Enable = true;//开始计时器,即超时时间。若达到了超时时间则说明连接断开
Thread.Sleep(100000);//一会儿后再重新监听是否已掉线
}
}
private void timer_Tick(..)
{
SendThread.Suspend();
尝试重新连接
if(连接上)
{
SendThread.Resume();
}
}
//bool running = true; //是否仍需运行
private void recv()
{
while(running)
{
string s = 接收到的信息;
if(!s.StartWith("c2")) //假定c2是响应代码
{
客户端重新连接;
}
}
}
private void deamo ()
{
while(running)
{
send("c1");//假定c1是控制代码
Thread.Sleep(100000);//一会儿后再重新监听是否已掉线
}
}