开发者

C# multi threading query

I am trying to write a program in C# that will connect to aroun开发者_StackOverflow中文版d 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!


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.


Take a look at the Task Parallel Library.

Speficically Data Parallelism.

You could also use PLINQ if you wanted.


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


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 :)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜