I need to write two things at the same time in the console. I have to display the partial results from when a recursive function comes back from recursion (i will have a wait time here) and in some other part of the screen I have to write the percentage of the stack that is full.
This must be done at the same time.
How do I do this in C#?
Edit: Also the progress must be updated.
You can set the position for writing using various properties in the
Consoleclass, such asCursorLeftandCursorTop. You can’t write to two positions at exactly the same time – just write to one location and then immediately write to another. That should be close enough.Two options to avoid race conditions:
Perform all the console writes in a single thread, e.g. using a producer/consumer queue of writes
Use locking – just have a method which does the complete “set position and write” operation within a lock.