且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#应用程序启动时运行的代码吗?

更新时间:2023-01-30 08:31:35

在正常情况下,WPF创建方法(应用程序的入口点)为您。您的选择

Under normal circumstances, WPF creates the Main method (the entrypoint of the application) for you. Your options


  • 创建为 Application.Startup 事件,并把你的代码中有。或者,您可以覆盖 OnStartup() 方法。

  • 如果这是太晚了你,把你的代码中的应用的参构造器(它可能不存在,但你可以创建一个)。

  • 如果连这是为时已晚,你可以创建自己的的Main()方法。 有几种方法如何做到这一点。也许最简单的就是把它放在另一个类,并告诉Visual Studio中要在项目的属性来使用这个方法。

  • Create a handler for the Application.Startup event and put your code there. Alternatively, you can override the OnStartup() method.
  • If that's too late for you, put your code in the App's parameterless constructor (it probably doesn't exist, but you can create it).
  • If even that's too late, you can create your own Main() method. There are several ways how to do that. Probably the easiest is to put it in another class and tell Visual Studio you want to use this method in the project's properties.

在该另一方面,你说你得到一些不起眼的XAML解析错误。也许你应该弄清楚究竟是什么意思呢?

On the other hand, you said you're getting some obscure XAML parsing errors. Maybe you should figure out what exactly do they mean?