public static List <ProcessRunning> GetProcesses(Process[] array) { return(array.Aggregate(new List <ProcessRunning>(), (newList, process) => { var item = new ProcessRunning { Id = process.Id, Name = process.ProcessName }; try { item.Description = process.MainModule.FileVersionInfo.FileDescription; item.Path = process.MainModule.FileName; item.Version = process.MainModule.FileVersionInfo.FileVersion; item.MemoryAllocation = process.MainModule.ModuleMemorySize.ToString(); } catch { item.Description = item.Path = item.Version = item.MemoryAllocation = "Access denied"; } newList.Add(item); return newList; })); }
void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) { if (theDebugger.Debugger == null) { return; } if (theDebugger.Debugger.IsEvaluating) { return; } bool newIsRunning = theDebugger.ProcessState == DebuggerProcessState.Running; if (newIsRunning == isRunning) { return; } var dnProcess = theDebugger.Debugger.Processes.FirstOrDefault(); if (dnProcess == null) { return; } isRunning = newIsRunning; int id = Interlocked.Increment(ref isRunningId); if (!isRunning) { return; } var process = GetProcessById(dnProcess.ProcessId); if (process == null) { return; } Timer timer = null; timer = new Timer(a => { timer.Dispose(); if (id == isRunningId) { if (dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished) { return; } dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { if (id == isRunningId) { ProcessRunning?.Invoke(this, new DebuggedProcessRunningEventArgs(process)); } })); } }, null, WAIT_TIME_MS, Timeout.Infinite); }
void DebuggedProcessRunningNotifier_ProcessRunning(object sender, DebuggedProcessRunningEventArgs e) => ProcessRunning?.Invoke(this, e);