vb.net 判断是否在IDE中执行的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15292758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Way to determine whether executing in IDE or not?
提问by CJ7
In C#/VBin Visual Studio 2010, is there way in the code to determine whether the program is currently running in the IDE or not?
在C#/VBin 中Visual Studio 2010,代码中有没有办法确定程序当前是否在 IDE 中运行?
eg. If ProgramRunningInIDE Then MessageBox.Show exc.Message
回答by Morrison Cole
You could check if the debugger is attached with:
您可以检查调试器是否附加了:
System.Diagnostics.Debugger.IsAttached
This essentially does the same thing.
这基本上做同样的事情。
回答by fjdumont
There is an IsInDesignModeproperty you can use. In some circumstances it isn't accurate, though, so you additionally may want to check the UsageMode.
有一个IsInDesignMode你可以使用属性。但是,在某些情况下它不准确,因此您可能还需要检查UsageMode。
public static bool IsRunningInIdeContext
{
get {
if (DesignerProperties.IsInDesignMode)
return true;
return LicenseManager.UsageMode == LicenseUsageMode.Designtime;
}
}

