Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

This is christhu,I have a C# Multithreading question.

I have list of 100 devices in an array. I ping each device, it takes considerable time to get the status of 100 devices one by one. The code is here:

for (int i = 0; i<= arr.Length; i++)
{
   row = table.NewRow();
   remoteIP = arr[i].Trim().ToString();
   if (!string.IsNullOrEmpty(remoteIP))
   {
      PingReply reply = null;
      try
      {
          reply = new Ping().Send(remoteIP, 1000);
      }
      catch
      {
          row["Description"] = "Ping Failed";
                            
      }
}                               


I need to implement this using Multithreading as I heard that when we use Multithreading we can reduce the processing time.

Please Help Me
Posted
Updated 15-Feb-11 6:01am
v3

The Ping class has a SendAsync method.

That would be much, much better than creating threads.
 
Share this answer
 
if you are into CTP's then i can full heartedly recommend the Async library
download form
http://msdn.microsoft.com/en-us/vstudio/async.aspx[^]

and read a great article from our own Sacha Barber :)
Task Parallel Library : 1 of n[^]


that way you get to spend some time not only getting your task done, but learning something cool :)

of course the SendAsync mentioned above is a great way to just get it done. :)
 
Share this answer
 
if u want to use threads u can use backgorundworker as well

if need some help on backgroundworker, then its my pleasure to help u.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900