111,094
社区成员




int[] sResult = new int[255];//声成全局变量
for (int i = 0; i < 255; i++)
{
sResult[i]=0;//数据初始化
}
for (int i = 0; i < 255; i++)
{
ParameterizedThreadStart pts = new ParameterizedThreadStart(threadPing);
Thread thisThread = new Thread(pts);
string strIP = strGateWay + i.ToString();
//当前需要Ping的IP
object[] sendPara = new object[2];
sendPara[0] = strIP;
sendPara[1]= i;
thisThread.Start(strIP);
}
public void threadPing(object ip)
{
int index = (int)((object[])ip)[1];
string strIp = (string)((object[])ip)[0];;
if (IsPingIP(strIP))
{
sResult[index]=1;
}
else
{
sResult[index]=-1;
}
}
// 结果,
//数组中的 数据为-1 :表示失败;
//数组中的 数据为 0 :表示线程还在睡觉中,--ping 还没有返回;
//数组中的 数据为 1 :表示拼成功;
//
//这个,如果 sResult 中还有0 ,那你可以等一下,即用一个线程sleep一下,等到数组中没有0为止!
for (int i=0;i<10;i++)
{
Thread.Sleep(一万年);
}
int count = 0;
for (int i = 0; i < 255; i++)
{
//当前需要Ping的IP
string strIP = strGateWay + i.ToString();
new Thread(p =>
{
if (IsPingIP((string)p))
{
lock (arrOnline)
{
arrOnline.Add((string)p);
}
}
Interlocked.Increment(ref count);
}).Start(strIP);
}
while (count != 255)
{
Thread.Sleep(100);
}
int[] sResult = new int[255];//声成全局变量
for (int i = 0; i < 255; i++)
{
ParameterizedThreadStart pts = new ParameterizedThreadStart(threadPing);
Thread thisThread = new Thread(pts);
string strIP = strGateWay + i.ToString();
//当前需要Ping的IP
object[] sendPara = new object[2];
sendPara[0] = strIP;
sendPara[1]= i;
thisThread.Start(strIP);
}
public void threadPing(object ip)
{
int index = (int)((object[])ip)[1];
string strIp = (string)((object[])ip)[0];;
if (IsPingIP(strIP))
{
sResult[index]=true;
}
else
{
sResult[index]=false;
}
}