From 7193eb08d179080038115700cd91cf36c099329d Mon Sep 17 00:00:00 2001 From: MonkSoul Date: Mon, 27 Mar 2023 13:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=90=20=E5=AE=8C=E5=96=84=20`Serve.Run`?= =?UTF-8?q?=20=E5=9C=A8=20`WinForm`=20=E4=B8=AD=E4=BD=BF=E7=94=A8=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handbook/docs/serverun.mdx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/handbook/docs/serverun.mdx b/handbook/docs/serverun.mdx index 4ff66de33c3..c1cdb9fef09 100644 --- a/handbook/docs/serverun.mdx +++ b/handbook/docs/serverun.mdx @@ -543,13 +543,15 @@ Serve.Run(GenericRunOptions.Default 更多发布命令说明可查阅微软官方文档 [https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish) -## 2.0.10 在 `Winform/WPF` 桌面中使用 +## 2.0.10 在 `WinForm/WPF` 桌面中使用 -在 `Winform` 或 `WPF` 中使用,请确保 `Serve.Run()` 在桌面应用程序之前初始化: +在 `WinForm` 或 `WPF` 中使用,请确保 `Serve.Run()` 在桌面应用程序之前初始化: -- **Winform** +- **WinForm** + +```cs showLineNumbers {5,11,14-17} +using System.Runtime.Loader; -```cs showLineNumbers {3,9} namespace WinFormsApp2; internal static class Program @@ -560,6 +562,12 @@ internal static class Program // 如果在 4.8.0 之前版本无返回值 var host = Serve.Run(silence: true); // 静默启动 + // 监听关闭事件 + AssemblyLoadContext.Default.Unloading += (ctx) => + { + host.Dispose(); + }; + ApplicationConfiguration.Initialize(); Application.Run(new Form1()); }