Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Console.Write write a full line on laptop

Tags:

vb.net

cmd

I sometimes work on a laptop locally and sometimes remote into a desktop machine.

Both have the same OS and version:

OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.19045 N/A Build 19045

But when I run a project that runs as a console application, I get different results depending on whether the solution is on the laptop or the desktop machine.

On my desktop machine running the project where there is a loop with this code:

  System.Console.Write($"{vbCr}{"".PadLeft(Console.CursorLeft, " "c)}")
  System.Console.Write($"{vbCr}Getting info for table: {tbl.Name}")

causes that line to get overwritten (as intended), on my laptop, that works as effectively a writeline (not what I want).

Why? And what do I do so that it works correctly on the laptop?

like image 555
jmoreno Avatar asked Mar 02 '26 04:03

jmoreno


1 Answers

Thanks to a hint by Dai, I was able to fix the problem. Apparently Console.CursorLeft isn't updated in real time, by adding System.Console.Out.Flush() before the write's, it is now acting correctly on my laptop. Buffer size was the same on both machines.

Still not quite sure of why this was happening (I would have expected different behavior if CursorLeft was zero or some other value), but it does fix my immediate problem.

like image 180
jmoreno Avatar answered Mar 05 '26 05:03

jmoreno