Пример #1
0
        /// <summary>
        /// Create a new instance of the server process, returning its process ID.
        /// Returns 0 on failure.
        /// </summary>
        private int CreateNewServerProcess()
        {
            // As far as I can tell, there isn't a way to use the Process class to
            // create a process with no stdin/stdout/stderr, so we use P/Invoke.
            // This code was taken from MSBuild task starting code.

            NativeMethods.STARTUPINFO startInfo = new NativeMethods.STARTUPINFO();
            startInfo.cb         = Marshal.SizeOf(startInfo);
            startInfo.hStdError  = NativeMethods.InvalidHandle;
            startInfo.hStdInput  = NativeMethods.InvalidHandle;
            startInfo.hStdOutput = NativeMethods.InvalidHandle;
            startInfo.dwFlags    = NativeMethods.STARTF_USESTDHANDLES;
            uint dwCreationFlags = NativeMethods.NORMAL_PRIORITY_CLASS | NativeMethods.CREATE_NO_WINDOW;

            NativeMethods.PROCESS_INFORMATION processInfo = new NativeMethods.PROCESS_INFORMATION();

            CompilerServerLogger.Log("Attempting to create process '{0}'", serverExecutablePath);

            bool success = NativeMethods.CreateProcess(
                serverExecutablePath,
                null,                                        // command line
                NativeMethods.NullPtr,                       // process attributes
                NativeMethods.NullPtr,                       // thread attributes
                false,                                       // don't inherit handles
                dwCreationFlags,
                NativeMethods.NullPtr,                       // inherit environment
                Path.GetDirectoryName(serverExecutablePath), // current directory
                ref startInfo,
                out processInfo);

            if (success)
            {
                CompilerServerLogger.Log("Successfully created process with process id {0}", processInfo.dwProcessId);
                NativeMethods.CloseHandle(processInfo.hProcess);
                NativeMethods.CloseHandle(processInfo.hThread);
                return(processInfo.dwProcessId);
            }
            else
            {
                CompilerServerLogger.Log("Failed to create process. GetLastError={0}", Marshal.GetLastWin32Error());
                return(0);
            }
        }
Пример #2
0
        /// <summary>
        /// Create a new instance of the server process, returning its process ID.
        /// Returns 0 on failure.
        /// </summary>
        private int CreateNewServerProcess()
        {
            // As far as I can tell, there isn't a way to use the Process class to 
            // create a process with no stdin/stdout/stderr, so we use P/Invoke.
            // This code was taken from MSBuild task starting code.

            NativeMethods.STARTUPINFO startInfo = new NativeMethods.STARTUPINFO();
            startInfo.cb = Marshal.SizeOf(startInfo);
            startInfo.hStdError = NativeMethods.InvalidHandle;
            startInfo.hStdInput = NativeMethods.InvalidHandle;
            startInfo.hStdOutput = NativeMethods.InvalidHandle;
            startInfo.dwFlags = NativeMethods.STARTF_USESTDHANDLES;
            uint dwCreationFlags = NativeMethods.NORMAL_PRIORITY_CLASS | NativeMethods.CREATE_NO_WINDOW;

            NativeMethods.PROCESS_INFORMATION processInfo = new NativeMethods.PROCESS_INFORMATION();

            CompilerServerLogger.Log("Attempting to create process '{0}'", serverExecutablePath);

            bool success = NativeMethods.CreateProcess(
                serverExecutablePath,
                null,                                        // command line
                NativeMethods.NullPtr,                       // process attributes
                NativeMethods.NullPtr,                       // thread attributes
                false,                                       // don't inherit handles
                dwCreationFlags,
                NativeMethods.NullPtr,                       // inherit environment
                Path.GetDirectoryName(serverExecutablePath), // current directory
                ref startInfo,
                out processInfo);

            if (success)
            {
                CompilerServerLogger.Log("Successfully created process with process id {0}", processInfo.dwProcessId);
                NativeMethods.CloseHandle(processInfo.hProcess);
                NativeMethods.CloseHandle(processInfo.hThread);
                return processInfo.dwProcessId;
            }
            else
            {
                CompilerServerLogger.Log("Failed to create process. GetLastError={0}", Marshal.GetLastWin32Error());
                return 0;
            }
        }