public void WrapDiagnositcProcessProperties()
        {
            using (var process = Process.GetCurrentProcess())
            {
                var processWrapper = new ProcessWrapper(process);

                Assert.Equal(process.Id, processWrapper.Id);
                Assert.Equal(process.ProcessName, processWrapper.Name);
                Assert.False(processWrapper.HasExited);
                Assert.Null(processWrapper.ExitTime);
            }
        }
예제 #2
0
        public void ExitTimeSetWhenProcessExits()
        {
            using (var process = Process.Start(new ProcessStartInfo("cmd") { CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }))
            {
                var processWrapper = new ProcessWrapper(process);

                Assert.Null(processWrapper.ExitTime);
                Assert.False(processWrapper.HasExited);

                process.KillAndWaitForExit();

                Assert.True(processWrapper.HasExited);
                Assert.NotNull(processWrapper.ExitTime);
            }
        }
예제 #3
0
        public IProcess GetProcessById(Int32 processId)
        {
            lock (processCache)
            {
                IProcess process = null;

                try
                {
                    if (processCache.TryGetValue(processId, out process) && !process.HasExited)
                        return process;

                    processCache[processId] = process = new ProcessWrapper(Process.GetProcessById(processId));
                }
                catch (Exception)
                {
                    processCache.Remove(processId);
                }

                return process ?? new UnknownProcess(processId);
            }
        }