在控制台关闭时阻止应用程序退出

Bag*_*nny 5 c# console winforms

我用来AllocConsole()在winform应用程序中打开一个控制台.

如何在控制台关闭时阻止应用程序退出?

编辑

我不希望在控制台中显示完成百分比的更新

    void bkpDBFull_PercentComplete(object sender, PercentCompleteEventArgs e)
    {
        AllocConsole();
        Console.Clear();
        Console.WriteLine("Percent completed: {0}%.", e.Percent);
    }
Run Code Online (Sandbox Code Playgroud)

我尝试使用richtextBox作为替代方案

       s =(e.Percent.ToString());
       richTextBox1.Clear();
       richTextBox1.AppendText("Percent completed:  " +s +"%");
Run Code Online (Sandbox Code Playgroud)

但我无法及时看到完成百分比更新.它仅在100%完成时出现.

还有其他选择

Roh*_*ats 0

请参考这里的答案。正如答案中提到的,有no way to stop the application from getting closed.

但作为一种解决方法,您可以own text output solution在其中一个答案中进行描述。