Answer the question
In order to leave comments, you need to log in
Simultaneous text output and input?
Good afternoon.
In a console application, text is displayed at any time, text input to the console is also active.
When a user is typing text and a message is being written at that time, it turns out something like this nonsense:
How to implement parallel output and input of text so that the output text is not written on the text that the user writes?
Answer the question
In order to leave comments, you need to log in
I understand the output comes from another thread? Then you need to synchronize the threads, something like
lock(некая глобальная переменная)
{
var top = Console.CursorTop;
var left = Console.CursorLeft;
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.Write(DateTime.Now.ToShortDateString());
Console.CursorTop = top;
Console.CursorLeft = left;
}
There are several ways.
1. You save the input to the buffer one by one (ReadKey), without showing it, and then redraw everything together. Roughly speaking, keep the whole screen and prev. output in memory and redraw it every time you press a key. A la Telnet.
2. As mentioned above, lock.
3. Write in a separate console through a shared file, Named Pipe or console arguments.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question