Program.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; 6 using System.Threading; 7 using Microsoft.CommandPalette.Extensions; 8 9 namespace ProcessMonitorExtension; 10 11 public class Program 12 { 13 [MTAThread] 14 public static void Main(string[] args) 15 { 16 if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer") 17 { 18 using ExtensionServer server = new(); 19 var extensionDisposedEvent = new ManualResetEvent(false); 20 var extensionInstance = new SampleExtension(extensionDisposedEvent); 21 22 // We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called. 23 // This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object. 24 // If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate. 25 server.RegisterExtension(() => extensionInstance); 26 27 // This will make the main thread wait until the event is signalled by the extension class. 28 // Since we have single instance of the extension object, we exit as soon as it is disposed. 29 extensionDisposedEvent.WaitOne(); 30 } 31 else 32 { 33 Console.WriteLine("Not being launched as a Extension... exiting."); 34 } 35 } 36 }