Multithreading in a console application in C#?

Need to do the following (gruberova):


console application produces different actions in an infinite loop. It took a string input from the user. If you just put Console.ReadLine(), we get an interruption of the cycle and waiting for input.


Had the idea to take user input in another thread. revered Doku made in another thread. in the generated stream Console.ReadLine() does not work.


I understand the fact that ReadLine and WriteLine in fact use stdin and stdout, and they're on the main application thread?


If so, tell me how it is possible to realize the data input from the user without causing the waiting for input (the main program needs to run without stopping).
October 10th 19 at 05:22
4 answers
October 10th 19 at 05:24
Solution
Example call Console.WriteLine() from several threads — the canonical example vstrechalis on the Internet on every corner, as an illustration of multithreading. Therefore, the idea of blocking stdin and stdout is wrong.

On the other hand, perhaps ReadLine behaves differently. I agree with the previous comment — you need to make an infinite loop in a thread, and interactively work mostly.
October 10th 19 at 05:26
To make the program logic in a separate thread, but mostly to work interactively...
October 10th 19 at 05:28
Delegates and invoke to help You, in fact You have the app with the "interface".
October 10th 19 at 05:30
thank you very much for the help

Find more questions by tags multithreadingC#