怎么判断程序是在VS里按F5运行的,还是在资源浏览器里双击运行的?

解决方案 »

  1.   

    Program starting itself is the same.
    But you can detect whether a debugger is attached (VS is a debugger):
    using System;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (System.Diagnostics.Debugger.IsAttached)          //<-------
                {
                    Console.WriteLine("A debugger is attached");
                }
                Console.ReadLine();
            }
        }
    }