如何暂停正在调试的Windows控制台程序 [英] How to pause a Windows console program being debugged

查看:295
本文介绍了如何暂停正在调试的Windows控制台程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当程序结束时,当控制台控制台程序调整时,控制台关闭 >并且没有机会看到输出。我如何保持开放?

When a C# or VB.Net console program is debugged the console closes as soon as the program ends and there is no opportunity to see the output. How do I keep it open?

推荐答案

我经常看到这样的问题。通常建议使用Console.ReadKey()或类似的东西,但这不适合生产使用。我的偏好是简单地把断点放在Main的最后一行,或者像这样的地方。

I often see questions like this. Often the suggestion is to use Console.ReadKey() or something like that but that is inappropriate for production use. My preference is to simply put a breakpoint on the last line of Main, or somewhere like that.

然而,我认为一个很好的选择是使用Debugger.IsAttached来确定如果控制台程序正在调试。以下是如何使用它的简单示例。这是C#代码,但我希望很容易转换成VB .Net。

I think however that a good alternative is to use Debugger.IsAttached to determine if the console program is being debugged. The following is a simple sample of how it can be used. This is C# code but I hope it is easy to convert to VB .Net.

using System;
namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Testing");
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.WriteLine("Debugging; press a key to continue...");
                Console.ReadKey();
            }
        }
    }
}

这篇关于如何暂停正在调试的Windows控制台程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆