如何在C#windows控制台应用程序中以单行更新校验和的进度

如何在C#windows控制台应用程序中以单行更新校验和的进度

本文介绍了如何在C#windows控制台应用程序中以单行更新校验和的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Is it possible to display the output in a single line by updating the percentage of a check disk progress in the same line. 
For example, if I want to show a percentage of a check disk progress, as of now in my output it shows in new line for every step of output.I'd just like to update the percentage of it in the same line , and not have to put each percentage on a new line.

Stage 1: Examining basic file system structure ...
Progress: 0 of 120832 done; Stage:  0%; Total:  0%; ETA:   0:05:50    
Progress: 1238 of 120832 done; Stage:  1%; Total:  0%; ETA:   0:05:50  
Progress: 3585 of 120832 done; Stage:  2%; Total:  1%; ETA:   0:05:47 
Progress: 6798 of 120832 done; Stage:  5%; Total:  1%; ETA:   0:00:58

this is how i get the output which is queried in a string and displayed on a textbox control





我尝试了什么:





What I have tried:

private void button1_Click(object sender, EventArgs e)
        {
            String cmd = textBox1.Text;
            if (cmd == "")
            {
                MessageBox.Show("Please Enter a command!", "Input error");
                return;
            }
            richTextBox1.Text = "Executing...\n";
            ExecuteCmd exe = new ExecuteCmd();
            exe.TestEvent += Exe_TestEvent;
            String result = exe.ExecuteCommand(cmd);
        }

        private void Exe_TestEvent(string s)
        {
            if (richTextBox1.InvokeRequired)
            {
                richTextBox1.Invoke(new MethodInvoker(delegate {
                    richTextBox1.Text += s + Environment.NewLine;
                    richTextBox1.SelectionStart = richTextBox1.Text.Length;
                    richTextBox1.ScrollToCaret();
                }));
            }
    }

推荐答案


这篇关于如何在C#windows控制台应用程序中以单行更新校验和的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 12:59