How can I do this in a C # console application on WriteLine, will it replace every line of the same with a for loop?

Possible duplicate:
How to update the current line in a C # Windows console application?

What I mean is that I have a for for for loops.

For (x=0; x<this.Length;x++) { for (y=0; y<this.Length;y++) { Console.WriteLine("Working on file " + images[x] + " please wait"); } } 

Line Console.WriteLine ("Work on the file" + images [x] + "please wait"); They will record in the console window each line of the file [x] under the line. I want him to write it once, and then rewrite the same line and so on. Not a line under a line. Like the count "Work on file 0001, please wait" Then the next line will replace the same "Work on file 0002, please wait"

I tried installing Console.Clear (); after Console.WriteLine, but then its like doestn flashing works smoothly.

+7
source share
4 answers

Instead of using WriteLine , which records the reverse feed and feed of the string, record only the return result. This places the cursor at the beginning of the line so that the next line is written on top of it:

 for (x=0; x<this.Length;x++) { for (y=0; y<this.Length;y++) { Console.Write("Working on file " + images[x] + " please wait\r"); } } 
+7
source

You can use Console.Write and prepend \ r as follows:

 Console.Write("\rWorking on file " + images[x] + " please wait"); 

And maybe add a few spaces at the end, just to make sure you delete the previous content.

+4
source

Use the Console.SetCursorPosition method: MSDN Console.SetCursorPosition

+3
source

By default, Console.WriteLine writes data to the console and terminates the line, so you cannot rewrite the same line this way.

I would suggest that it is better to have a line written for each processed image so that you can see which images were processed and what was not

0
source

All Articles