U
U
UrbanRider2011-02-04 15:10:06
C++ / C#
UrbanRider, 2011-02-04 15:10:06

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

4 answer(s)
T
tangro, 2011-02-05
@UrbanRider

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.

A
Alexander Korotaev, 2011-02-04
@aavezel

Move the logic of the program to a separate thread, but mostly work interactively ...

E
eforce, 2011-02-04
@eforce

Delegates and invoke to help you, in fact you have an application with an "interface".

U
UrbanRider, 2011-03-02
@UrbanRider

thank you all so much for your help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question