L
L
LiptonOlolo2016-10-24 15:58:05
C++ / C#
LiptonOlolo, 2016-10-24 15:58:05

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:
DrlaEZQC4pWd6m.png
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

2 answer(s)
S
Sergey, 2016-10-24
@senal

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;
}

M
Melz, 2016-10-27
@melz

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 question

Ask a Question

731 491 924 answers to any question