TerminateProcess.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics; 6 using Microsoft.CommandPalette.Extensions.Toolkit; 7 8 namespace ProcessMonitorExtension; 9 10 internal sealed partial class TerminateProcess : InvokableCommand 11 { 12 private readonly ProcessItem _process; 13 private readonly ProcessListPage _owner; 14 15 public TerminateProcess(ProcessItem process, ProcessListPage owner) 16 { 17 _process = process; 18 _owner = owner; 19 Icon = new IconInfo("\ue74d"); 20 Name = "End task"; 21 } 22 23 public override CommandResult Invoke() 24 { 25 var process = Process.GetProcessById(_process.ProcessId); 26 process.Kill(); 27 _owner.UpdateItems(); 28 return CommandResult.KeepOpen(); 29 } 30 }