tags:

views:

66

answers:

2

Hi all,

I'm using a foreach loop to query remote PCs, for some reason querying a certain PCs the program sticks on the PC (maybe it's been turned off mid query), how can I wait for awhile (although a fixed length of time would be no good as some can take minutes to query others 30 mins) and then move on to the next PC?

foreach (String pc in pcs)
            {
                if (bg_worker.CancellationPending) break; 
               ...
} 

Thanks

Jade

A: 

See http://www.codeplex.com/smartthreadpool It supports work item cancelation.

unclepaul84
+2  A: 

Use a threadpool to query for several hosts simultaneously. This does three things for you:

  1. Dramatically reduce your total scan time, since currently your program is likely spending a lot of time waiting for responses.
  2. Allow you to use the built-in mechanisms to terminate asynchronous threads to implement your timeout
  3. Means a "stuck" PC won't stop all scanning while waiting to timeout - just that thread
Joel Coehoorn