コード例 #1
0
        /// <summary>
        /// Allocate a console if application started from within windows GUI.
        /// Detects the presence of an existing console associated with the application and
        /// attaches itself to it if available.
        /// </summary>
        public static void AllocateConsoleIfNecessary()
        {
            if (Debugger.IsAttached)
            {
                Available = false;
                return; // Don't create console under debugger
            }

            if (ParentProcessFinder.RunAsService())
            {
                Available = false;
                return; // Don't create console if running as a service
            }

            ForceAllocateConsole();
        }
コード例 #2
0
        public static void Init()
        {
            // Check for null here is necessary, because thread name can only be set once and unit test runner tends to do so before us
            // We better not set it here at all to let WorkerRunnerProcess32 to set it.
            //if (Thread.CurrentThread.Name == null)
            //{
            //    Thread.CurrentThread.Name = "Main thread";
            //}

            Tracer.Create(Process.GetCurrentProcess().ProcessName);

            DebugConsole.AllocateConsoleIfNecessary();

            Tracer.Info("Process {0} with ID {1} starts.", Process.GetCurrentProcess().ProcessName, Process.GetCurrentProcess().Id);

            RunAsService = ParentProcessFinder.RunAsService();
            if (RunAsService)
            {
                ShimmedService = new ShimmedService {
                    ServiceName = Process.GetCurrentProcess().ProcessName
                };
            }
        }