Skip to content

Commit

Permalink
😐 完善 Serve.RunWinForm 中使用说明
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Mar 27, 2023
1 parent 8d14e04 commit 7193eb0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions handbook/docs/serverun.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
Expand Down

0 comments on commit 7193eb0

Please sign in to comment.