|
2 | 2 | // The Microsoft Corporation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
| 5 | +using Microsoft.CommandPalette.Extensions; |
| 6 | +using Shmuelie.WinRTServer; |
| 7 | +using Shmuelie.WinRTServer.CsWinRT; |
5 | 8 | using System;
|
6 | 9 | using System.Threading;
|
7 |
| -using Microsoft.CommandPalette.Extensions; |
| 10 | +using System.Threading.Tasks; |
8 | 11 |
|
9 | 12 | namespace TemplateCmdPalExtension;
|
10 | 13 |
|
11 | 14 | public class Program
|
12 | 15 | {
|
13 | 16 | [MTAThread]
|
14 |
| - public static void Main(string[] args) |
| 17 | + public static async Task Main(string[] args) |
15 | 18 | {
|
16 | 19 | if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
|
17 | 20 | {
|
18 |
| - using ExtensionServer server = new(); |
19 |
| - var extensionDisposedEvent = new ManualResetEvent(false); |
20 |
| - var extensionInstance = new TemplateCmdPalExtension(extensionDisposedEvent); |
21 |
| - |
| 21 | + await using global::Shmuelie.WinRTServer.ComServer server = new(); |
| 22 | + ManualResetEvent extensionDisposedEvent = new(false); |
| 23 | + |
22 | 24 | // We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
|
23 | 25 | // This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
|
24 | 26 | // 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 | + TemplateCmdPalExtension extensionInstance = new(extensionDisposedEvent); |
| 28 | + server.RegisterClass<TemplateCmdPalExtension, IExtension>(() => extensionInstance); |
| 29 | + server.Start(); |
| 30 | + |
27 | 31 | // This will make the main thread wait until the event is signalled by the extension class.
|
28 | 32 | // Since we have single instance of the extension object, we exit as soon as it is disposed.
|
29 | 33 | extensionDisposedEvent.WaitOne();
|
|
0 commit comments