Answer the question
In order to leave comments, you need to log in
Multithreading in C# console application?
You need to do the following (roughly speaking):
the console application performs various actions in an endless loop. A string input from the user was required. If we just put Console.ReadLine(), we get a break in the loop and wait for input.
There was an idea to take out input of the user in other flow. read to dock carried out in other flow. in the created thread Console.ReadLine() does not work.
As far as I understand, the fact is that ReadLine and WriteLine essentially use stdin and stdout, and they are already occupied by the main application thread?
If so, please tell me how it is possible to get input from the user without waiting for input (the main program should run without stopping).
Answer the question
In order to leave comments, you need to log in
The example of calling Console.WriteLine() from multiple parallel threads is a canonical example found on every corner of the internet as an illustration of multithreading. Therefore, the idea of blocking stdin and stdout is wrong.
On the other hand, perhaps ReadLine behaves differently. Then I agree with the previous comment - you need to take out an infinite loop into a thread, and work interactively in the main.
Move the logic of the program to a separate thread, but mostly work interactively ...
Delegates and invoke to help you, in fact you have an application with an "interface".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question