Using Console.WriteLine during Console.ReadLine
c#, console-application, mono
Solution
You could use the Console.CursorLeft and Console.CursorRight properties to note the cursors location, shift it, output your text, then shift it back.
Edit: Here's a sample I just threw together, works well based on the 60 seconds of testing I threw at it.
int fooCursorTop = Console.CursorTop + 1;
var timer2 = new System.Timers.Timer(1000);
timer2.Elapsed += new System.Timers.ElapsedEventHandler(delegate
{
int tempCursorLeft = Console.CursorLeft;
int tempCursorTop = Console.CursorTop;
Console.CursorLeft = 0;
Console.CursorTop = fooCursorTop;
Console.WriteLine("Foo");
Console.CursorLeft = tempCursorLeft;
Console.CursorTop = tempCursorTop;
fooCursorTop++;
});
timer2.Start();
string input = string.Empty;
while (input != "quit")
{
input = Console.ReadLine();
Console.CursorTop = fooCursorTop;
Console.WriteLine(input);
fooCursorTop += 2;
}
Problem
I've got the following code: ``` bool loop = true; LongbowWorkerThread Worker = new LongbowWorkerThread(); Thread w = new Thread(Worker.UpdateChannel); w.Start(); string inText = string.Empty; while (loop) { inText = Console.ReadLine(); Console.WriteLine(inText); } ``` At this point, the worker thread simply echoes a string every 5000ms. The problem is that the printed string overlaps the user's already-entered text, which isn't ideal and looks quite ugly (although it doesn't affect the actual data returned by Console.ReadLine.) Is there a way to prevent this overlap?