如何检测C#Windows窗体code为Visual Studio中执行? [英] How to detect that C# Windows Forms code is executed within Visual Studio?

查看:174
本文介绍了如何检测C#Windows窗体code为Visual Studio中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个变量或preprocessor不变,允许知道code为Visual Studio中的?

Is there a variable or a preprocessor constant that allows to know that the code is executed within the context of Visual Studio?

推荐答案

尝试<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.isattached.aspx\">Debugger.IsAttached或<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx\">DesignMode财产或获得 ProcessName 或组合,相应的

Try Debugger.IsAttached or DesignMode property or get ProcessName or a combination, as appropriate

Debugger.IsAttached // or                                       
LicenseUsageMode.Designtime // or 
System.Diagnostics.Process.GetCurrentProcess().ProcessName

下面是一个<一个href=\"http://voidnish.word$p$pss.com/2009/06/21/checking-for-design-mode/\">sample

public static class DesignTimeHelper {
    public static bool IsInDesignMode {
        get {
            bool isInDesignMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime || Debugger.IsAttached == true;

            if (!isInDesignMode) {
                using (var process = Process.GetCurrentProcess()) {
                    return process.ProcessName.ToLowerInvariant().Contains("devenv");
                }
            }

            return isInDesignMode;
        }
    }
}

这篇关于如何检测C#Windows窗体code为Visual Studio中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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