Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 985
Aadi Droid Avatar asked Jun 16 '11 10:06

Aadi Droid


2 Answers

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.

like image 67
CodesInChaos Avatar answered Sep 21 '22 23:09

CodesInChaos


Take a look at the Task Parallel Library.

Speficically Data Parallelism.

You could also use PLINQ if you wanted.

like image 32
George Duckett Avatar answered Sep 17 '22 23:09

George Duckett