// // // // // $Revision: 2206 $ // using System; using System.Collections.Generic; using System.Threading; using Debugger.Wrappers.CorDebug; namespace Debugger { public partial class NDebugger { List processCollection = new List(); public event EventHandler ProcessStarted; public event EventHandler ProcessExited; public IList Processes { get { return processCollection.AsReadOnly(); } } public Process DebugActiveProcess(uint handle, string filename) { InitDebugger(GetProgramVersion(filename)); Process p = new Process(this,this.CorDebug.DebugActiveProcess(handle,0)); AddProcess(p); return p; } private Process debugActiveProcess(uint handle, string filename) { InitDebugger(GetProgramVersion(filename)); Process p = new Process(this,this.CorDebug.DebugActiveProcess(handle,0)); AddProcess(p); return p; } internal Process GetProcess(ICorDebugProcess corProcess) { foreach (Process process in Processes) { if (process.CorProcess == corProcess) { return process; } } return null; //throw new DebuggerException("Process is not in collection"); } internal void AddProcess(Process process) { processCollection.Add(process); OnProcessStarted(process); } internal void RemoveProcess(Process process) { processCollection.Remove(process); OnProcessExited(process); if (processCollection.Count == 0) { // Exit callback and then terminate the debugger this.MTA2STA.AsyncCall( delegate { this.TerminateDebugger(); } ); } } protected virtual void OnProcessStarted(Process process) { if (ProcessStarted != null) { ProcessStarted(this, new ProcessEventArgs(process)); } } protected virtual void OnProcessExited(Process process) { if (ProcessExited != null) { ProcessExited(this, new ProcessEventArgs(process)); } } } }