private void ScanWithMultThreads(string subIP, int start, int end)
{ int ipCount = end - start + 1;
DateTime starttime = new DateTime();
starttime = DateTime.Now;
Thread[] scanThreads=new Thread[ipCount];
for(int i=0;i<ipCount;i++)
{
Scan scan=new Scan
{
ip=string.Format("{0},{1}",subIP,start+1),
form=this};
scanThreads[i]=new Thread(scan.CheckComputer);
scanThreads[i].IsBackground=true;
scanThreads[i].Start();
ThreadPool.QueueUserWorkItem(new WaitCallback(testMethod), scanThreads[i]);
}
WaitHandle.WaitAll(scanThreads);
listBoxStatus.Items.Add("扫描用时为:" + (DateTime.Now - starttime).TotalMilliseconds);
}
public void testMethod(object objEvent)
{
//TODO: Add your code here
ManualResetEvent e = (ManualResetEvent)objEvent;
e.Set();
}
----------------------------------------------------------------------------------------------------------
这是部分代码 程序运行后 出现两个错误 如下:
错误 2 参数 1: 无法从“System.Threading.Thread[]”转换为“System.Threading.WaitHandle[]” C:\Users\liu\documents\visual studio 2010\Projects\ScanComputer\ScanComputer\MainForm.cs 75 29 ScanComputer
错误 1 与“System.Threading.WaitHandle.WaitAll(System.Threading.WaitHandle[])”最匹配的重载方法具有一些无效参数 C:\Users\liu\documents\visual studio 2010\Projects\ScanComputer\ScanComputer\MainForm.cs 75 10 ScanComputer
-------------------------------------------------------------------------------------------------------------
求高人指点 到底哪个地方错误 尽量详细些 嘿嘿 多谢
{ int ipCount = end - start + 1;
DateTime starttime = new DateTime();
starttime = DateTime.Now;
Thread[] scanThreads=new Thread[ipCount];
for(int i=0;i<ipCount;i++)
{
Scan scan=new Scan
{
ip=string.Format("{0},{1}",subIP,start+1),
form=this};
scanThreads[i]=new Thread(scan.CheckComputer);
scanThreads[i].IsBackground=true;
scanThreads[i].Start();
ThreadPool.QueueUserWorkItem(new WaitCallback(testMethod), scanThreads[i]);
}
WaitHandle.WaitAll(scanThreads);
listBoxStatus.Items.Add("扫描用时为:" + (DateTime.Now - starttime).TotalMilliseconds);
}
public void testMethod(object objEvent)
{
//TODO: Add your code here
ManualResetEvent e = (ManualResetEvent)objEvent;
e.Set();
}
----------------------------------------------------------------------------------------------------------
这是部分代码 程序运行后 出现两个错误 如下:
错误 2 参数 1: 无法从“System.Threading.Thread[]”转换为“System.Threading.WaitHandle[]” C:\Users\liu\documents\visual studio 2010\Projects\ScanComputer\ScanComputer\MainForm.cs 75 29 ScanComputer
错误 1 与“System.Threading.WaitHandle.WaitAll(System.Threading.WaitHandle[])”最匹配的重载方法具有一些无效参数 C:\Users\liu\documents\visual studio 2010\Projects\ScanComputer\ScanComputer\MainForm.cs 75 10 ScanComputer
-------------------------------------------------------------------------------------------------------------
求高人指点 到底哪个地方错误 尽量详细些 嘿嘿 多谢
这个scanThreads参数吗 类型是Thread[]类型的 帮看看错?