Reputation: 26517
What is the best way in c# to determine whether the programmer is running the program via IDE or its user?
Upvotes: 28
Views: 4939
Reputation: 7282
if (System.Diagnostics.Debugger.IsAttached) {
// You are debugging
}
Upvotes: 35
Reputation: 3487
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;
}
}
Upvotes: 7