1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
5
using System.ComponentModel;
6
using System.Diagnostics;
9
using System.Windows.Forms;
11
using ICSharpCode.Core;
12
using ICSharpCode.SharpDevelop.Debugging;
13
using ICSharpCode.SharpDevelop.Gui;
15
namespace ICSharpCode.SharpDevelop.Services
17
public class AttachToProcessForm : AbstractAttachToProcessForm
19
class ProcessListViewItem : ListViewItem
24
public ProcessListViewItem(Process process, WindowsDebugger debugger)
26
this.process = process;
28
var modules = process.Modules.Cast<ProcessModule>().Where(
29
m => m.ModuleName.StartsWith("mscor", StringComparison.InvariantCultureIgnoreCase));
31
managed = modules.Count() > 0;
34
string fileName = Path.GetFileName(process.MainModule.FileName);
36
SubItems.Add(process.Id.ToString());
37
SubItems.Add(process.MainWindowTitle);
38
SubItems.Add(GetManagedString(managed));
41
public Process Process {
42
get { return process; }
45
public bool IsManaged {
46
get { return managed; }
49
static string GetManagedString(bool managed)
52
return StringParser.Parse("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.AttachToProcessForm.Managed}");
58
protected override void RefreshProcessList(ListView listView, bool showNonManaged)
60
listView.Items.Clear();
61
WindowsDebugger debugger = (WindowsDebugger)DebuggerService.CurrentDebugger;
62
Process currentProcess = Process.GetCurrentProcess();
63
foreach (Process process in Process.GetProcesses()) {
65
if (process.HasExited) continue;
66
// Prevent attaching to our own process.
67
if (currentProcess.Id != process.Id) {
68
ProcessListViewItem item = new ProcessListViewItem(process, debugger);
69
if (showNonManaged || item.IsManaged) {
71
listView.Items.Add(item);
74
} catch (Win32Exception) {