Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

threading

Status
Not open for further replies.

Ju1c3

MIS
Apr 3, 2007
43
US
ok, i am trying to creat my own ip scanner just like angry ip scanner. i like it, but i wanted to add something that i felt needed to be added such as your own ip so when i am on another network i dont have to do an ip config. well i have it all set up and work, it is just it is very slow. i mean it takes 10 seconds just to do 10 ip addresses. i noticed when angry does it, it has 63 threads running at once to speed this process up. i have tried to speed it up as much as possible without threads by doing less calculating in the for statements and whatnot, but it still isnt fast enough. i am trying to figure out how to do threading myself like angry. here is the code i am excuting, i know its very noobish code and all, but i havent programmed in like 2 years now so i am just getting back into it. so if someone could help me with the threading part, i would appreciate it very much.


varibles: F1-F4 are ip from and T is too
Code:
private void button3_Click(object sender, EventArgs e)
        {
            Ping pinger = new Ping();
            PingOptions options = new PingOptions();

            options.DontFragment = true;

            string data = "aaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            string begAddy = F1.Text + "." + F2.Text + "." + F3.Text + ".";
            int f4int = Convert.ToInt32(F4.Text);
            int t4int = Convert.ToInt32(T4.Text);
            IPAddress ipaddy;

            for (int z = f4int; z <= t4int; z++)
            {
                ipaddy = IPAddress.Parse(begAddy + z);
                PingReply pingRep = pinger.Send(ipaddy, timeout, buffer, options);

                if (pingRep.Status == IPStatus.Success)
                {
                    IPHostEntry temp = new IPHostEntry();
                    temp = Dns.GetHostEntry(ipaddy);
                    textBox1.AppendText("Address: " + pingRep.Address.ToString() + ":  " + temp.HostName.ToString() + "\r\n");
                }
                
                progressBar2.Increment(2);
            }
        }
 
You can create a multi-threaded application by using the System.Threading.Timer. You can specify the timer interval and a callback method that actually runs the code. This would allow you to run 10,15, whatever processes in parallel I believe rather than in succession.If you enclose this in a Windows Service, it's a way to run a set of processes at a specific interval.

If you would like a code example, let me know.
 
well what if the reply shows back up before the time interval has passed? thats my big question
 
Timer class is for timed jobs.. I dont see any timed jobs in this problem. Use System.Threading.Thread class to create "worker" threads that deal with each of the IP address. The logic would be to put the "working" part, i.e. the code inside the loop into thread function and let it run in parallel with others.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top