Вы можете использовать библиотеку OswaldTechnologies.Extensions.Hosting.WindowsFormsLifetime
, которую я написал для выполнения sh this.
Установочный пакет:
Install-Package OswaldTechnologies.Extensions.Hosting.WindowsFormsLifetime
Program
класс до этого по умолчанию. NET Core Шаблон Win Forms:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Преобразование Program
класса в класс после установки пакета:
static class Program
{
static void Main()
{
CreateHostBuilder().Build().Run();
}
public static IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder(Array.Empty<string>())
.UseWindowsFormsLifetime<Form1>()
.ConfigureServices((hostContext, services) =>
{
});
}
Вы можете просмотреть код в репозитории Github: https://github.com/oswald-technologies/WindowsFormsLifetime