110,535
社区成员
发帖
与我相关
我的任务
分享
DelegateMethod dm3 = delegate()
{
var devices = CaptureDeviceList.Instance;
if (devices.Count > 0)
{
captureDeviceList = devices;
foreach (WinPcapDevice device in captureDeviceList)
{
if (device.Name.ToLower().EndsWith(adapterID.ToLower()))
{
currentDevice = device;
if (currentDevice != null)
{
currentDevice.OnPcapStatistics += new StatisticsModeEventHandler(currentDevice_OnPcapStatistics);
int readTimeoutMilliseconds = 1000;
currentDevice.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
currentDevice.StartCapture();
break;
}
}
}
}
};
if (threadStatistic == null)
{
threadStatistic = new Thread(new ThreadStart(dm3));
}
threadStatistic.Start();
DelegateMethod dm2 = delegate()
{
if (currentDevice != null)
{
Thread.Sleep(2000);
currentDevice.StopCapture();
currentDevice.Close();
currentDevice.OnPcapStatistics -= currentDevice_OnPcapStatistics;
currentDevice = null;
}
};
threadStatistic = new Thread(new ThreadStart(dm2));
threadStatistic.Start();
Thread.Sleep(2000);
threadStatistic.Abort();
threadStatistic = null;
private void currentDevice_OnPcapStatistics(object sender, StatisticsModeEventArgs e)
{
//代码省略...
//这个事件仅在第一次Start()后才执行,纳闷...
}
DelegateMethod dm2 = delegate()
{
if (currentDevice != null)
{
Thread.Sleep(2000);
currentDevice.StopCapture();
currentDevice.Close();
currentDevice.OnPcapStatistics -= currentDevice_OnPcapStatistics;
currentDevice = null;
}
};
//先终止这个进程。
threadStatistic.Abort();
threadStatistic = new Thread(new ThreadStart(dm2));
threadStatistic.Start();
Thread.Sleep(2000);
threadStatistic.Abort();
threadStatistic = null;