golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/embeddable-dll-service/csharp/DemoUI/Program.cs (about) 1 /* SPDX-License-Identifier: MIT 2 * 3 * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved. 4 */ 5 6 using System; 7 using System.Threading; 8 using System.Diagnostics; 9 using System.Windows.Forms; 10 11 namespace DemoUI 12 { 13 static class Program 14 { 15 [STAThread] 16 static void Main(string[] args) 17 { 18 if (args.Length == 3 && args[0] == "/service") 19 { 20 var t = new Thread(() => 21 { 22 try 23 { 24 var currentProcess = Process.GetCurrentProcess(); 25 var uiProcess = Process.GetProcessById(int.Parse(args[2])); 26 if (uiProcess.MainModule.FileName != currentProcess.MainModule.FileName) 27 return; 28 uiProcess.WaitForExit(); 29 Tunnel.Service.Remove(args[1], false); 30 } 31 catch { } 32 }); 33 t.Start(); 34 Tunnel.Service.Run(args[1]); 35 t.Interrupt(); 36 return; 37 } 38 Application.SetHighDpiMode(HighDpiMode.SystemAware); 39 Application.EnableVisualStyles(); 40 Application.SetCompatibleTextRenderingDefault(false); 41 Application.Run(new MainWindow()); 42 } 43 } 44 }