Exemplo n.º 1
0
 /// <summary>
 ///     Initialize a new <see cref="WardenProcess"/> instance that is associated with the specified process
 ///     <paramref name="info"/>.
 /// </summary>
 /// <param name="info">The process information of a system process object.</param>
 /// <param name="filteredImages"></param>
 internal WardenProcess(ProcessInfo?info, IEnumerable <string>?filteredImages = null) : this(filteredImages)
 {
     if (info is null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     Initialize(info);
 }
Exemplo n.º 2
0
 private Process(string machineName, bool isRemoteMachine, int processId, ProcessInfo?processInfo)
 {
     GC.SuppressFinalize(this);
     _processInfo          = processInfo;
     _machineName          = machineName;
     _isRemoteMachine      = isRemoteMachine;
     _processId            = processId;
     _haveProcessId        = true;
     _outputStreamReadMode = StreamReadMode.Undefined;
     _errorStreamReadMode  = StreamReadMode.Undefined;
 }
Exemplo n.º 3
0
        private void RecycleProcess()
        {
            var process = _processInfo?.Process;

            if (process != null && !process.HasExited)
            {
                process.Kill();
            }

            _processInfo = StartWorkerProcess();
        }
Exemplo n.º 4
0
        static void CheckTimer()
        {
            if (_tmr == null)
            {
                //Get the information immediately for the current caller
                _info = ResourceMonitor.GetProcessInformation();

                _tmr          = new Timer(3000);
                _tmr.Elapsed += Watch;
                _tmr.Start();
            }
        }
Exemplo n.º 5
0
        private string GetPipeName()
        {
            var process = _processInfo?.Process;

            if (process != null && !process.HasExited)
            {
                return(_processInfo.Value.PipeName);
            }

            _processInfo = StartWorkerProcess();
            return(_processInfo.Value.PipeName);
        }
Exemplo n.º 6
0
 /// <devdoc>
 ///    <para>
 ///       Discards any information about the associated process
 ///       that has been cached inside the process component. After <see cref='System.Diagnostics.Process.Refresh'/> is called, the
 ///       first request for information for each property causes the process component
 ///       to obtain a new value from the associated process.
 ///    </para>
 /// </devdoc>
 public void Refresh()
 {
     _processInfo              = null;
     _threads                  = null;
     _modules                  = null;
     _exited                   = false;
     _haveWorkingSetLimits     = false;
     _haveProcessorAffinity    = false;
     _havePriorityClass        = false;
     _haveExitTime             = false;
     _havePriorityBoostEnabled = false;
     RefreshCore();
 }
Exemplo n.º 7
0
 /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 ///     <see langword="true"/> if the current object is equal to the <paramref name="other"/> parameter; otherwise,
 ///     <see langword="false"/>.
 /// </returns>
 public bool Equals(ProcessInfo?other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Name == other.Name && Image == other.Image && ParentProcessId == other.ParentProcessId && Id == other.Id && CommandLine == other.CommandLine && WorkingDirectory == other.WorkingDirectory &&
            CreationDate == other.CreationDate && SessionId == other.SessionId);
 }
Exemplo n.º 8
0
 // UI thread
 void InitializeNonInitializedBuffers_UI(ProcessInfo?info)
 {
     uiDispatcher.VerifyAccess();
     if (info is null)
     {
         return;
     }
     foreach (var bufferState in bufferStates)
     {
         if (bufferState.Process is null)
         {
             bufferState.SetUnderlyingStream(info.Stream, info.Process);
         }
     }
 }
Exemplo n.º 9
0
        public ProcessInfo?GetProcessInfo(string process_name)
        {
            ProcessList processList = MemoryHelper.GetProcessList();
            ProcessInfo?processInfo = null;

            foreach (Process process in processList.processes)
            {
                if (process.name == process_name)
                {
                    processInfo = MemoryHelper.GetProcessInfo(process.pid);
                    break;
                }
            }

            return(processInfo);
        }
Exemplo n.º 10
0
        /// <summary>Gets process infos for each process on the specified machine.</summary>
        /// <param name="machineName">The target machine.</param>
        /// <returns>An array of process infos, one per found process.</returns>
        public static ProcessInfo[] GetProcessInfos(string machineName)
        {
            ThrowIfRemoteMachine(machineName);

            // Iterate through all process IDs to load information about each process
            var processes = new List <ProcessInfo>();

            foreach (int pid in EnumerateProcessIds())
            {
                ProcessInfo?pi = CreateProcessInfo(pid);
                if (pi != null)
                {
                    processes.Add(pi);
                }
            }

            return(processes.ToArray());
        }
Exemplo n.º 11
0
        /// <summary>Gets process infos for each process on the specified machine.</summary>
        /// <param name="processNameFilter">Optional process name to use as an inclusion filter.</param>
        /// <param name="machineName">The target machine.</param>
        /// <returns>An array of process infos, one per found process.</returns>
        public static ProcessInfo[] GetProcessInfos(string?processNameFilter, string machineName)
        {
            ThrowIfRemoteMachine(machineName);

            // Iterate through all process IDs to load information about each process
            int[] pids      = GetProcessIds(machineName);
            var   processes = new ArrayBuilder <ProcessInfo>(processNameFilter is null ? pids.Length : 0);

            foreach (int pid in pids)
            {
                ProcessInfo?pi = CreateProcessInfo(pid, processNameFilter);
                if (pi != null)
                {
                    processes.Add(pi);
                }
            }

            return(processes.ToArray());
        }
Exemplo n.º 12
0
        public static Process[] GetProcessesByName(string?processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);

            int[] procIds   = ProcessManager.GetProcessIds();
            var   processes = new ArrayBuilder <Process>(string.IsNullOrEmpty(processName) ? procIds.Length : 0);

            // Iterate through all process IDs to load information about each process
            foreach (int pid in procIds)
            {
                ProcessInfo?processInfo = ProcessManager.CreateProcessInfo(pid, processName);
                if (processInfo != null)
                {
                    processes.Add(new Process(machineName, isRemoteMachine: false, pid, processInfo));
                }
            }

            return(processes.ToArray());
        }
Exemplo n.º 13
0
        /// <summary>Gets process infos for each process on the specified machine.</summary>
        /// <param name="processNameFilter">Optional process name to use as an inclusion filter.</param>
        /// <param name="machineName">The target machine.</param>
        /// <returns>An array of process infos, one per found process.</returns>
        public static ProcessInfo[] GetProcessInfos(string?processNameFilter, string machineName)
        {
            Debug.Assert(processNameFilter is null, "Not used on Linux");
            ThrowIfRemoteMachine(machineName);

            // Iterate through all process IDs to load information about each process
            IEnumerable <int>          pids      = EnumerateProcessIds();
            ArrayBuilder <ProcessInfo> processes = default;

            foreach (int pid in pids)
            {
                ProcessInfo?pi = CreateProcessInfo(pid);
                if (pi != null)
                {
                    processes.Add(pi);
                }
            }

            return(processes.ToArray());
        }
Exemplo n.º 14
0
        /// <summary>Gets process infos for each process on the specified machine.</summary>
        /// <param name="machineName">The target machine.</param>
        /// <returns>An array of process infos, one per found process.</returns>
        public static ProcessInfo[] GetProcessInfos(string machineName)
        {
            ThrowIfRemoteMachine(machineName);
            int[] procIds = GetProcessIds(machineName);

            // Iterate through all process IDs to load information about each process
            var reusableReader = new ReusableTextReader();
            var processes      = new List <ProcessInfo>(procIds.Length);

            foreach (int pid in procIds)
            {
                ProcessInfo?pi = CreateProcessInfo(pid, reusableReader);
                if (pi != null)
                {
                    processes.Add(pi);
                }
            }

            return(processes.ToArray());
        }
Exemplo n.º 15
0
        private void processes_comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                section_list_box.Items.Clear();
                result_list_view.Items.Clear();
                new_scan_btn.Enabled     = true;
                valueTypeList.Enabled    = true;
                compareTypeList.Enabled  = true;
                section_list_box.Enabled = true;

                ProcessInfo?maybeProcessInfo = processManager.GetProcessInfo(processes_comboBox.Text);
                if (maybeProcessInfo is null)
                {
                    msg.Text = "No process information found.";
                    return;
                }
                ProcessInfo processInfo = (ProcessInfo)maybeProcessInfo;

                Util.DefaultProcessID = processInfo.pid;
                ProcessMap processMap = MemoryHelper.GetProcessMaps(processInfo.pid);
                if (processMap is null)
                {
                    msg.Text = "No process maps found.";
                    return;
                }

                processManager.MappedSectionList.InitMemorySectionList(processMap);

                section_list_box.BeginUpdate();
                for (int i = 0; i < processManager.MappedSectionList.Count; ++i)
                {
                    section_list_box.Items.Add(processManager.MappedSectionList.GetSectionName(i), false);
                }
                section_list_box.EndUpdate();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 16
0
        public GameInfo()
        {
            string process_name   = "";
            string section_name   = "";
            ulong  id_offset      = 0;
            ulong  version_offset = 0;
            int    section_prot   = 0;

            switch (Util.Version)
            {
            case 702:
                process_name   = GAME_INFO_7_02_PROCESS_NAME;
                section_name   = GAME_INFO_7_02_SECTION_NAME;
                id_offset      = GAME_INFO_7_02_ID_OFFSET;
                version_offset = GAME_INFO_7_02_VERSION_OFFSET;
                section_prot   = GAME_INFO_7_02_SECTION_PROT;
                break;

            case 672:
                process_name   = GAME_INFO_6_72_PROCESS_NAME;
                section_name   = GAME_INFO_6_72_SECTION_NAME;
                id_offset      = GAME_INFO_6_72_ID_OFFSET;
                version_offset = GAME_INFO_6_72_VERSION_OFFSET;
                section_prot   = GAME_INFO_6_72_SECTION_PROT;
                break;

            case 505:
                process_name   = GAME_INFO_5_05_PROCESS_NAME;
                section_name   = GAME_INFO_5_05_SECTION_NAME;
                id_offset      = GAME_INFO_5_05_ID_OFFSET;
                version_offset = GAME_INFO_5_05_VERSION_OFFSET;
                section_prot   = GAME_INFO_5_05_SECTION_PROT;
                break;

            default:
                break;
            }

            try
            {
                ProcessManager processManager   = new ProcessManager();
                ProcessInfo?   maybeProcessInfo = processManager.GetProcessInfo(process_name);
                if (maybeProcessInfo is null)
                {
                    return;
                }
                ProcessInfo processInfo = (ProcessInfo)maybeProcessInfo;

                MemoryHelper      memoryHelper      = new MemoryHelper(false, processInfo.pid);
                MappedSectionList mappedSectionList = processManager.MappedSectionList;
                ProcessMap        processMap        = MemoryHelper.GetProcessMaps(processInfo.pid);
                if (processMap is null)
                {
                    return;
                }

                mappedSectionList.InitMemorySectionList(processMap);
                List <MappedSection> sectionList = mappedSectionList.GetMappedSectionList(section_name, section_prot);

                if (sectionList.Count != 1)
                {
                    return;
                }

                GameID  = System.Text.Encoding.Default.GetString(memoryHelper.ReadMemory(sectionList[0].Start + id_offset, 16));
                GameID  = GameID.Trim(new char[] { '\0' });
                Version = System.Text.Encoding.Default.GetString(memoryHelper.ReadMemory(sectionList[0].Start + version_offset, 16));
                Version = Version.Trim(new char[] { '\0' });
            }
            catch
            {
            }
        }
Exemplo n.º 17
0
 internal RemoteTestUtil(Dispatcher dispatcher)
 {
     _dispatcher  = dispatcher;
     _processInfo = StartWorkerProcess();
 }
Exemplo n.º 18
0
        private async Task <TestResult> RunTestAsyncInternal(AssemblyInfo assemblyInfo, bool retry, CancellationToken cancellationToken)
        {
            try
            {
                var         commandLineArguments = GetCommandLineArguments(assemblyInfo, useSingleQuotes: false);
                var         resultsFilePath      = GetResultsFilePath(assemblyInfo);
                var         resultsDir           = Path.GetDirectoryName(resultsFilePath);
                var         htmlResultsFilePath  = Options.IncludeHtml ? GetResultsFilePath(assemblyInfo, "html") : null;
                var         processResultList    = new List <ProcessResult>();
                ProcessInfo?procDumpProcessInfo  = null;

                // NOTE: xUnit doesn't always create the log directory
                Directory.CreateDirectory(resultsDir !);

                // Define environment variables for processes started via ProcessRunner.
                var environmentVariables = new Dictionary <string, string>();
                Options.ProcDumpInfo?.WriteEnvironmentVariables(environmentVariables);

                if (retry && File.Exists(resultsFilePath))
                {
                    ConsoleUtil.WriteLine("Starting a retry. Tests which failed will run a second time to reduce flakiness.");
                    try
                    {
                        var doc = XDocument.Load(resultsFilePath);
                        foreach (var test in doc.XPathSelectElements("/assemblies/assembly/collection/test[@result='Fail']"))
                        {
                            ConsoleUtil.WriteLine($"  {test.Attribute("name")!.Value}: {test.Attribute("result")!.Value}");
                        }
                    }
                    catch
                    {
                        ConsoleUtil.WriteLine("  ...Failed to identify the list of specific failures.");
                    }

                    // Copy the results file path, since the new xunit run will overwrite it
                    var backupResultsFilePath = Path.ChangeExtension(resultsFilePath, ".old");
                    File.Copy(resultsFilePath, backupResultsFilePath, overwrite: true);

                    // If running the process with this varialbe added, we assume that this file contains
                    // xml logs from the first attempt.
                    environmentVariables.Add("OutputXmlFilePath", backupResultsFilePath);
                }

                // NOTE: xUnit seems to have an occasional issue creating logs create
                // an empty log just in case, so our runner will still fail.
                File.Create(resultsFilePath).Close();

                var start             = DateTime.UtcNow;
                var dotnetProcessInfo = ProcessRunner.CreateProcess(
                    ProcessRunner.CreateProcessStartInfo(
                        Options.DotnetFilePath,
                        commandLineArguments,
                        workingDirectory: Path.GetDirectoryName(assemblyInfo.AssemblyPath),
                        displayWindow: false,
                        captureOutput: true,
                        environmentVariables: environmentVariables),
                    lowPriority: false,
                    cancellationToken: cancellationToken);
                Logger.Log($"Create xunit process with id {dotnetProcessInfo.Id} for test {assemblyInfo.DisplayName}");

                var xunitProcessResult = await dotnetProcessInfo.Result;
                var span = DateTime.UtcNow - start;

                Logger.Log($"Exit xunit process with id {dotnetProcessInfo.Id} for test {assemblyInfo.DisplayName} with code {xunitProcessResult.ExitCode}");
                processResultList.Add(xunitProcessResult);
                if (procDumpProcessInfo != null)
                {
                    var procDumpProcessResult = await procDumpProcessInfo.Value.Result;
                    Logger.Log($"Exit procdump process with id {procDumpProcessInfo.Value.Id} for {dotnetProcessInfo.Id} for test {assemblyInfo.DisplayName} with code {procDumpProcessResult.ExitCode}");
                    processResultList.Add(procDumpProcessResult);
                }

                if (xunitProcessResult.ExitCode != 0)
                {
                    // On occasion we get a non-0 output but no actual data in the result file.  The could happen
                    // if xunit manages to crash when running a unit test (a stack overflow could cause this, for instance).
                    // To avoid losing information, write the process output to the console.  In addition, delete the results
                    // file to avoid issues with any tool attempting to interpret the (potentially malformed) text.
                    var resultData = string.Empty;
                    try
                    {
                        resultData = File.ReadAllText(resultsFilePath).Trim();
                    }
                    catch
                    {
                        // Happens if xunit didn't produce a log file
                    }

                    if (resultData.Length == 0)
                    {
                        // Delete the output file.
                        File.Delete(resultsFilePath);
                        resultsFilePath     = null;
                        htmlResultsFilePath = null;
                    }
                }

                Logger.Log($"Command line {assemblyInfo.DisplayName}: {Options.DotnetFilePath} {commandLineArguments}");
                var standardOutput = string.Join(Environment.NewLine, xunitProcessResult.OutputLines) ?? "";
                var errorOutput    = string.Join(Environment.NewLine, xunitProcessResult.ErrorLines) ?? "";

                var testResultInfo = new TestResultInfo(
                    exitCode: xunitProcessResult.ExitCode,
                    resultsFilePath: resultsFilePath,
                    htmlResultsFilePath: htmlResultsFilePath,
                    elapsed: span,
                    standardOutput: standardOutput,
                    errorOutput: errorOutput);

                return(new TestResult(
                           assemblyInfo,
                           testResultInfo,
                           commandLineArguments,
                           processResults: ImmutableArray.CreateRange(processResultList)));
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to run {assemblyInfo.AssemblyPath} with {Options.DotnetFilePath}. {ex}");
            }
        }
Exemplo n.º 19
0
 static void Watch(object sender, ElapsedEventArgs e)
 {
     _info = ResourceMonitor.GetProcessInformation();
     //_memCounter = new System.Diagnostics.PerformanceCounter("Mono Memory", "Total Physical Memory", String.Empty, Environment.MachineName);
 }
        static void CheckTimer()
        {
            if (_tmr == null)
            {
                //Get the information immediately for the current caller
                _info = ResourceMonitor.GetProcessInformation();

                _tmr = new Timer(3000);
                _tmr.Elapsed += Watch;
                _tmr.Start();
            }
        }
 static void Watch(object sender, ElapsedEventArgs e)
 {
     _info = ResourceMonitor.GetProcessInformation();
     //_memCounter = new System.Diagnostics.PerformanceCounter("Mono Memory", "Total Physical Memory", String.Empty, Environment.MachineName);
 }
Exemplo n.º 22
0
        private async Task <TestResult> RunTestAsyncInternal(AssemblyInfo assemblyInfo, bool retry, CancellationToken cancellationToken)
        {
            try
            {
                var         commandLineArguments = GetCommandLineArguments(assemblyInfo);
                var         resultsFilePath      = GetResultsFilePath(assemblyInfo);
                var         resultsDir           = Path.GetDirectoryName(resultsFilePath);
                var         processResultList    = new List <ProcessResult>();
                ProcessInfo?procDumpProcessInfo  = null;

                // NOTE: xUnit doesn't always create the log directory
                Directory.CreateDirectory(resultsDir);

                // Define environment variables for processes started via ProcessRunner.
                var environmentVariables = new Dictionary <string, string>();
                Options.ProcDumpInfo?.WriteEnvironmentVariables(environmentVariables);

                if (retry && File.Exists(resultsFilePath))
                {
                    // Copy the results file path, since the new xunit run will overwrite it
                    var backupResultsFilePath = Path.ChangeExtension(resultsFilePath, ".old");
                    File.Copy(resultsFilePath, backupResultsFilePath, overwrite: true);

                    ConsoleUtil.WriteLine("Starting a retry. It will run once again tests failed.");
                    // If running the process with this varialbe added, we assume that this file contains
                    // xml logs from the first attempt.
                    environmentVariables.Add("OutputXmlFilePath", backupResultsFilePath);
                }

                // NOTE: xUnit seems to have an occasional issue creating logs create
                // an empty log just in case, so our runner will still fail.
                File.Create(resultsFilePath).Close();

                var start            = DateTime.UtcNow;
                var xunitProcessInfo = ProcessRunner.CreateProcess(
                    ProcessRunner.CreateProcessStartInfo(
                        Options.XunitPath,
                        commandLineArguments,
                        displayWindow: false,
                        captureOutput: true,
                        environmentVariables: environmentVariables),
                    lowPriority: false,
                    cancellationToken: cancellationToken);
                Logger.Log($"Create xunit process with id {xunitProcessInfo.Id} for test {assemblyInfo.DisplayName}");

                // Now that xunit is running we should kick off a procDump process if it was specified
                if (Options.ProcDumpInfo != null)
                {
                    var procDumpInfo      = Options.ProcDumpInfo.Value;
                    var procDumpStartInfo = ProcessRunner.CreateProcessStartInfo(
                        procDumpInfo.ProcDumpFilePath,
                        ProcDumpUtil.GetProcDumpCommandLine(xunitProcessInfo.Id, procDumpInfo.DumpDirectory),
                        captureOutput: true,
                        displayWindow: false);
                    Directory.CreateDirectory(procDumpInfo.DumpDirectory);
                    procDumpProcessInfo = ProcessRunner.CreateProcess(procDumpStartInfo, cancellationToken: cancellationToken);
                    Logger.Log($"Create procdump process with id {procDumpProcessInfo.Value.Id} for xunit {xunitProcessInfo.Id} for test {assemblyInfo.DisplayName}");
                }

                var xunitProcessResult = await xunitProcessInfo.Result;
                var span = DateTime.UtcNow - start;

                Logger.Log($"Exit xunit process with id {xunitProcessInfo.Id} for test {assemblyInfo.DisplayName} with code {xunitProcessResult.ExitCode}");
                processResultList.Add(xunitProcessResult);
                if (procDumpProcessInfo != null)
                {
                    var procDumpProcessResult = await procDumpProcessInfo.Value.Result;
                    Logger.Log($"Exit procdump process with id {procDumpProcessInfo.Value.Id} for {xunitProcessInfo.Id} for test {assemblyInfo.DisplayName} with code {procDumpProcessResult.ExitCode}");
                    processResultList.Add(procDumpProcessResult);
                }

                if (xunitProcessResult.ExitCode != 0)
                {
                    // On occasion we get a non-0 output but no actual data in the result file.  The could happen
                    // if xunit manages to crash when running a unit test (a stack overflow could cause this, for instance).
                    // To avoid losing information, write the process output to the console.  In addition, delete the results
                    // file to avoid issues with any tool attempting to interpret the (potentially malformed) text.
                    var resultData = string.Empty;
                    try
                    {
                        resultData = File.ReadAllText(resultsFilePath).Trim();
                    }
                    catch
                    {
                        // Happens if xunit didn't produce a log file
                    }

                    if (resultData.Length == 0)
                    {
                        // Delete the output file.
                        File.Delete(resultsFilePath);
                        resultsFilePath = null;
                    }
                }

                var commandLine = GetCommandLine(assemblyInfo);
                Logger.Log($"Command line {assemblyInfo.DisplayName}: {commandLine}");
                var standardOutput = string.Join(Environment.NewLine, xunitProcessResult.OutputLines) ?? "";
                var errorOutput    = string.Join(Environment.NewLine, xunitProcessResult.ErrorLines) ?? "";
                var testResultInfo = new TestResultInfo(
                    exitCode: xunitProcessResult.ExitCode,
                    resultsFilePath: resultsFilePath,
                    elapsed: span,
                    standardOutput: standardOutput,
                    errorOutput: errorOutput);

                return(new TestResult(
                           assemblyInfo,
                           testResultInfo,
                           commandLine,
                           isFromCache: false,
                           processResults: ImmutableArray.CreateRange(processResultList)));
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to run {assemblyInfo.AssemblyPath} with {Options.XunitPath}. {ex}");
            }
        }
Exemplo n.º 23
0
        /// <devdoc>
        ///     Helper method for checking preconditions when accessing properties.
        /// </devdoc>
        /// <internalonly/>
        private void EnsureState(State state)
        {
            if ((state & State.Associated) != (State)0)
            {
                if (!Associated)
                {
                    throw new InvalidOperationException(SR.NoAssociatedProcess);
                }
            }

            if ((state & State.HaveId) != (State)0)
            {
                if (!_haveProcessId)
                {
                    if (_haveProcessHandle)
                    {
                        SetProcessId(ProcessManager.GetProcessIdFromHandle(_processHandle !));
                    }
                    else
                    {
                        EnsureState(State.Associated);
                        throw new InvalidOperationException(SR.ProcessIdRequired);
                    }
                }
                if ((state & State.HaveNonExitedId) == State.HaveNonExitedId)
                {
                    ThrowIfExited(refresh: false);
                }
            }

            if ((state & State.IsLocal) != (State)0 && _isRemoteMachine)
            {
                throw new NotSupportedException(SR.NotSupportedRemote);
            }

            if ((state & State.HaveProcessInfo) != (State)0)
            {
                if (_processInfo == null)
                {
                    if ((state & State.HaveNonExitedId) != State.HaveNonExitedId)
                    {
                        EnsureState(State.HaveNonExitedId);
                    }
                    _processInfo = ProcessManager.GetProcessInfo(_processId, _machineName);
                    if (_processInfo == null)
                    {
                        throw new InvalidOperationException(SR.NoProcessInfo);
                    }
                }
            }

            if ((state & State.Exited) != (State)0)
            {
                if (!HasExited)
                {
                    throw new InvalidOperationException(SR.WaitTillExit);
                }

                if (!_haveProcessHandle)
                {
                    throw new InvalidOperationException(SR.NoProcessHandle);
                }
            }
        }