-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessPurgerPackage.cs
More file actions
76 lines (70 loc) · 3.26 KB
/
ProcessPurgerPackage.cs
File metadata and controls
76 lines (70 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using EnvDTE;
using EnvDTE80;
using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using ProcessPurger.Extensions;
using Task = System.Threading.Tasks.Task;
namespace ProcessPurger
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[Guid(ProcessPurgerPackage.PackageGuidString)]
public sealed class ProcessPurgerPackage : AsyncPackage, IVsDebuggerEvents
{
public const string PackageGuidString = "8372a177-5b80-4468-a172-5e7bea6e74ab";
private DTE dte;
private IVsDebugger debugService;
private int DebuggedProcessId;
private uint debugCookie;
private ProcessMonitor processMonitor;
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
dte = await GetServiceAsync(typeof(DTE)) as DTE;
string msg = "The current Output Window object belongs to the ";
Assumes.Present(dte);
debugService = (IVsDebugger)GetGlobalService(typeof(SVsShellDebugger));
debugService.AdviseDebuggerEvents(this, out debugCookie);
}
int IVsDebuggerEvents.OnModeChange(DBGMODE dbgmodeNew)
{
switch (dbgmodeNew)
{
case DBGMODE.DBGMODE_Run:
if (DebuggedProcessId == 0)
{
// switch mainthread
Process debuggedProcess = dte.Debugger.DebuggedProcesses.Cast<Process>().FirstOrDefault(proc => System.Diagnostics.Process.GetProcessById(proc.ProcessID).GetParent().ProcessName.Contains("VsDebugConsole"));
//if (System.Diagnostics.Process.GetProcessById(debuggedProcess.ProcessID).GetParent().ProcessName.Contains("VsDebugConsole"))
if (debuggedProcess != null)
{
DebuggedProcessId = debuggedProcess.ProcessID;
processMonitor = new ProcessMonitor(DebuggedProcessId);
processMonitor.StartWatch();
}
}
break;
case DBGMODE.DBGMODE_Design:
Process debuggedProcesses = dte.Debugger.DebuggedProcesses.Cast<Process>().FirstOrDefault(process => process.ProcessID == DebuggedProcessId);
if (DebuggedProcessId != 0 && debuggedProcesses is null)
{
processMonitor.StopWatch();
processMonitor.KillChildProcesses();
processMonitor = null;
DebuggedProcessId = 0;
}
break;
}
return (int)dbgmodeNew;
}
}
}