如何为每个IP地址创建线程? [英] How to create threads to each Ip address?
本文介绍了如何为每个IP地址创建线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早安朋友,
我目前正在开发IP pinger,我想为每个IP地址创建线程,因此我想创建100个线程,每个线程使用一个IP地址,直到完成示例IP地址的过程为止:这是我的代码使用
Good Morning friends,
I am currently developing an IP pinger and I want to create threads for each IP address, so I want to create 100 thread each thread takes an IP address until I complete the course of the example IP address: This is the code i ''m using
string ip = "129168.";
for (int i = 0; i <256; i + +)
{
for (int j = 0 j <256; j + +)
{
string ip = newIP + i.ToString () + "." + J.ToString ();
ping(ip);//methode Ping
Application.DoEvents ();
}
}
这个想法就像ip扫描仪一样,它为每个IP地址创建一个线程来执行方法...我希望这很清楚
谢谢您.
this idea is like the ip scanner, for each IP address it create a thread to excute a methode...I hope that''s clear
thank you
推荐答案
您为什么不使用ThreadPool呢?您可以在其他类中实现该逻辑,然后使用ThreadPool.QueueUserWorkItem方法进行调用.
http://msdn.microsoft.com/zh-cn/library/system.threading.threadpool.queueuserworkitem%28v = vs.80%29.aspx [
Why don''t you use a ThreadPool then. You can implement the logic in a different class and invoke with ThreadPool.QueueUserWorkItem method.
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.queueuserworkitem%28v=vs.80%29.aspx[^]
看看带有GUI的简单Ping实用程序 [
这篇关于如何为每个IP地址创建线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文