C # multithreaded request

I am trying to write a program in C # that will connect to 400 computers and get some information, say that it retrieves a list of web services running on each computer. I guess I need a multi-threaded application to be able to quickly get information from such a huge number of servers. I'm pretty empty on how to get started working on this, could you guys get started on how to get started?

Thanks!

+6
source share
6 answers

I see no reason why you should use streams in your main logic. Use asynchronous APIs and assign their callback to the main thread. This way you get the benefits of asynchrony, but without most of the problems associated with streaming processing.

You will need multithreading in your logic code if the work you need to do with the data is expensive. And even then you, as a rule, can receive aways with parallelization, using free side effects.

+5
source

Take a look at the parallel task library .

Right Parallelism Data .

You can also use PLINQ if you want.

+2
source

You should also execute threads in parallel on a multi-core processor to improve performance.

My favorite links to this topic are below -

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

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

+1
source

Where and how do you get a list of these 400 servers for the query?

how often do you need to do this?

you can use the Windows service or schedule a task that calls your software, and in it you can make the foreach element in the list of servers and start calling such a server in another thread using the queue / pool of threads, but there is a maximum so that in any case you don’t started 400 threads.

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

0
source

Take a look at this library: Parallel Library Task . You can effectively use your system resources and manage your work easier than directly manage your flows.

0
source

Running a request on all 400 computers can have a significant impact on the server. 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 question, for example. a Task class.

Creating manual threads may not be a good idea, since they cannot be reused and take up quite a lot of memory / CPU to be created.

0
source

Source: https://habr.com/ru/post/890664/


All Articles