Aadi Droid
Aadi Droid

Reputation: 1739

C# multi threading query

I am trying to write a program in C# that will connect to around 400 computers and retrieve some information, lets say it retrieves the list of web services running on each computer. I am assuming I need a well threaded application to be able to retrieve info from such a huge number of servers really quick. I am pretty blank on how to start working on this, can you guys give me a head start as to how to begin!

Thanks!

Upvotes: 6

Views: 2493

Answers (6)

oleksii
oleksii

Reputation: 35925

There might be considerable impact on the server side when you start query all 400 computers. But you can take a look at Parallel LINQ (PLINQ), where you can limit the degree of parallelism.

You can also use thread pooling for this matter, e.g. a Task class.

Createing manual threads may not be a good idea, as they are not highly reusable and take quite a lot of memory/CPU to be created

Upvotes: 0

agent-j
agent-j

Reputation: 27943

Take a look at this library: Task Parallel Library. You can make efficient use of your system resources and manage your work easier than managing your threads directly.

Upvotes: 0

George Duckett
George Duckett

Reputation: 32448

Take a look at the Task Parallel Library.

Speficically Data Parallelism.

You could also use PLINQ if you wanted.

Upvotes: 2

Unmesh Kondolikar
Unmesh Kondolikar

Reputation: 9312

You should also execute the threads parallely on a multi-core CPU to enhance performance.

My favourite references on the topic are given below -

http://www.albahari.com/threading/

http://www.codeproject.com/KB/Parallel_Programming/NET4ParallelIntro.aspx

Upvotes: 1

CodesInChaos
CodesInChaos

Reputation: 108880

I see no reason why you should use threading in your main logic. Use asynchronous APIs and schedule their callback to the main thread. That way you get the benefits of asynchrony, but without most of the difficulty related to threading.

You'll only need multithreading in your logic code if the work you need to do on the data is that expensive. And even then you usually can get aways with parallelizing using side effect free functions.

Upvotes: 5

Davide Piras
Davide Piras

Reputation: 44605

Where and how do you get the list of those 400 servers to query?

how often do you need to do this?

you could use a windows service or schedule a task which invoke your software and in it you could do a foreach element in the server list and start a call to such server in a different thread using thread queue/pool, but there is a maximum so you won't start 400 threads all together anyway.

describe a bit better your solution and we see what you can do :)

Upvotes: 0

Related Questions