H
H
HappyMen2019-05-04 03:17:41
C++ / C#
HappyMen, 2019-05-04 03:17:41

C# how to make multithreading in checker?

For my development, I make a proxy checker
Let's say I have a proxy.txt file in which the proxy from each new line
I need the program to take each line and send, say, a get request to the server with this proxy "domain.com/api?proxy={hereproxy }" . And the answer was simply written down in another txt. And here is the problem, how to make the software multi-threaded. So that I can enter the number of threads. For so very slowly checks. If something is written (done) wrong, do not hit with a stick, just registered.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2019-05-04
@Dywar

You can not play with threads, it's better to use Task.
Task-Based Asynchronous Programming
Parallel.ForEach Method
When to use Parallel.ForEach and when to use PLINQ
Imagine that proxy.txt is a list of tasks, when you read the file you create them and pass them to the ThreadPool, it will distribute them among the CPU cores and allocate the required number of threads. Your task will be reduced only to "gluing" the results. You can write down the result immediately as soon as the task is over, or you can simply save it in the opportiv and write it down only at the end.
Have a look at Thread-Safe Collections

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question