WPF .net6 自定义启动入口 、 自定义Main函数、自定义 STAThread 方法

前言:

  为了解决程序开启自启动问题

参考资料

  Custom Entry Points in WPF on .NET Core 链接 https://blog.magnusmontin.net/2020/01/31/custom-entry-point-wpf-net-core/

  Creating a custom Main method in a WPF application 链接 https://www.meziantou.net/creating-a-custom-main-method-in-a-wpf-application.htm

  这两资料只看其一,不能成功设置。

自定义启动入口

  在点击项目文件,进入项目文件中添加如下图:

  

  如果不添加,可以在 ...\obj\Debug\net6.0-windows 目录下找到 App.g.cs 文件,此文件中定义了 Main 入口。

  所以必须添加  <ApplicationDefinition Remove="App.xaml" /> 项。

  在项目根目录下创建 “Program.CS”文件,再添加 Main函数,如下图:

  

  在Main方法中启动程序。如果发现程序,突然报错很多 蓝色线、红色线,重启 vs 2022 ,就消失了,然后再重新编译。

我的仓库

  我的代码仓库 https://github.com/qiqiqiyaya/WPF/tree/main/Lesson%2010%20Practice/Practice

  如果对你有帮助,给颗小星星

posted @ 2023-07-21 22:58  youliCC  阅读(248)  评论(0编辑  收藏  举报