在C#中,最好的方法是通过检测程序是由IDE还是用户运行来确定程序员正在运行程序的方式是什么?
if (System.Diagnostics.Debugger.IsAttached) {
// You are debugging
}
public static bool IsInVisualStudio
{
get
{
bool inIDE = false;
string[] args = System.Environment.GetCommandLineArgs();
if (args != null && args.Length > 0)
{
string prgName = args[0].ToUpper();
inIDE = prgName.EndsWith("VSHOST.EXE");
}
return inIDE;
}
}
args
是一个字符串数组,而不是一个字符串。 - Jon Skeet