110,526
社区成员
发帖
与我相关
我的任务
分享
//我自己设想的如下:
getMac.Start(new object[] { ip.ToString() });
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(timerCall), getMac, 500, 0);//500秒后关闭线程
System.Threading.Thread.Sleep(1000);//等待定时器的判断
//定时器
private void timerCall(object obj)
{
if (...)
{
getMac.Abort(); //关闭线程
}
result = "";
}
//线程
void doGetMac(object argument)
{
fun();//一个执行时间不固定的函数。注意:此函数不可重入!
}
delegate void a();
a f = func;
IAsyncResult result = f.BeginInvoke(delegate(IAsyncResult ar)
{
f.EndInvoke(ar);
}, null);
result.AsyncWaitHandle.WaitOne(500, false);