Question Advice please: Multithreaded WMI Query Client Application?

jiwisto

New member
Joined
Jan 28, 2013
Messages
2
Programming Experience
10+
Hi,

I am about to develeop an app that is going to query hundreds or even thousands of clients for some WMI-strings over the WAN. The app will be launched as using Scheduled Task or manually when needed, and will read an text file with hostnames to contact and peform the WMI-querys. The result will be saved in a new text file this as an example:

Hostname | Date | LastBootuptime | LoggedOnUser

A123456 | 20313-04-01 | 2013-02-15 | Joe Smith
A234567 | 20313-04-01 | 2013-03-29 | John Doe
A345678 | 20313-04-01 | 2013-03-02 | Sally Johnson

I´m sure that the only way to handle all thoose calls to a lot of clients, must be done as an multi threaded solution. This in order to maintain speed and handle all possible connection problems to some off-line clinets without have to waiting for each time out e.t.c.

Here comes the 1000 dollar question:

What code structure or threading model do you recommend me to use regarding the actual Multithreading solution to use to handle the client connection & WMI-querys for each clients in the text file?

Please give me a brief code example of how it could look regarding the thread calls of sub or function.
I have done a lot of reading on this but I'am still confused regarding which thread model to use like BackgroundWorker or ThreadPooli or whats more available. Need your expertise to get started, then I can move on with the rest.

Thanx in advance :sneakiness:
 
A shorter answer, within the Task Parallel Library are the loop constructs for parallel operations Parallel.ForEach and Parallel.For.

Essentially you use them exactly the same as you would classic For and For Each, but the syntax is a tiny bit different:

        Parallel.ForEach(SomeCollection, Sub(OneElement)
                                             DoSomethingWithElement(OneElement)
                                         End Sub)

        Parallel.For(LowerBoundInclusive, HigherBoundExclusive, Sub(ElementIndex)
                                                                    DoSomethingWithElementIndex(ElementIndex)
                                                                End Sub)


One thing that is different is that the order in which the elements will be processed cannot be predicted. The loop will not go "1, 2, 3, 4, ...". It might go "2, 3, 1, 4, ...". This is fairly important to remember. Also with Parallel.For, the high bound is exclusive.

This approach works well when you need to go through a source list and take advantage of all available processors. ThreadPool, BackgroundWorker, etc will also all work, but they will need a bit more code.
 
Back
Top