2
我有定时代码检查死对等。我使用System.Threading.Timer来做到这一点。检测代码的工作,我这样称呼它:c#线程计时器需要停止自己的异步套接字代码
Timer SocketKPATimer = new Timer(delegate { timedcode(state); }, null, 5000, 5000);
其中状态是所使用到
Socket handler = state.workSocket;
,后来成为StateObject ...
handler.Shutdown(SocketShutdown.Both);
//I need to stop the Timer here
的方法本身被定义作为 static void timedcode(StateObject state) {...}
现在的问题是,在我发现对端出现问题,我需要SocketKPATimer停止,而我不能。 如何修改时间码,以便我可以停止计时器?
是的,这确实是我的testcode。在创建SocketKPATimer之后,我确实需要移动'state.TimerThingy = SocketKPATimer;'否则代码在抛弃定时器时抛出nullreference异常。非常感谢你。 – ZoOl007