如何优化 Windows 启动时 WPF 应用程序的启动

发布于 2024-11-16 01:09:52 字数 244 浏览 1 评论 0 原文

我实现了一个 WPF 应用程序,并将其注册为在 Windows 启动时启动。我的应用程序是一个简单的登录应用程序,当用户登录时,它会出现在图标托盘中。问题是 Windows 启动后需要大约 30 秒才能显示出来。我尝试过 Ngen 但没有取得很大成功。我想避免实现闪屏。我希望我的 WPF 应用程序在 Windows 启动后“立即”出现,类似于 Windows Live Messenger 的操作。我可以做些什么来减少其启动时间?除了本地编码之外我还有其他选择吗? 谢谢。

I implemented a WPF app and had it registered to launch at windows startup. My app is a simple logon app which when the user is logged on appears in the icon tray.The problem is that it takes about 30 seconds to show itself after Windows startup. I've tried Ngen without great success. I would like to avoid implementing a splash screen. I would like my WPF app to appear "immediately" after Windows startup similar to what Windows Live Messenger does. Anything I can do so as to reduce its startup time? Do I have any other choice than to code it natively?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

分開簡單 2024-11-23 01:09:52

当计算机空闲时是否也需要 30 秒才能启动(即,如果在计算机不忙于加载 Windows 时通过双击启动它)?

在 Windows 启动期间,计算机通常会忙于处理大量事务,这可能会导致应用程序运行缓慢。那时你无能为力。

但是,有一些改进 WPF 应用程序启动的一般技巧:

  • 仅实例化最初实际需要向用户显示的控件
  • 降低控件/窗口的复杂性。
  • 不要在控件和控件的构造函数中执行任何耗时的操作。视窗
    • 如果磁盘正忙于处理其他内容(就像通常在 Windows 启动期间那样),即使是从本地磁盘读取文件之类的无害内容也可能非常耗时
    • 如果网络尚未完全初始化,Web 服务调用可能需要很长时间
    • 一个简单的解决方案是将繁重的工作卸载给 BackgroundWorker 或使用异步调用来执行 I/O 和网络请求

您还可以在 app.config 中放入一个设置code> 告诉运行时不要使用以下命令对程序集进行身份验证证书(此检查可能需要很长时间,尤其是冷启动):

<configuration>
  <runtime>
    <generatePublisherEvidence enabled="false"/> 
  </runtime>
</configuration>

MSDN 站点 应用程序启动时间

Does it also take 30 seconds to start when the computer is idle (i.e if you start it by double clicking when the computer is not busy loading windows)?

During windows startup, the computer is typically busy with a lot of stuff and that could cause slowness for your application. Not much you can do then.

But, some general tips for improving startup of a WPF application:

  • Only instantiate the controls you actually need to show to the user initially
  • Reduce the complexity of your controls/windows.
  • Don't do anything time consuming in the constructors of your controls & windows
    • Even innocent stuff like reading a file from local disk can be time consuming if the disk is busy with other stuff (like it normally is during windows startup)
    • Web service calls can take extra long time if the network hasn't been fully initialized yet
    • An easy solution is to offload heavy work to a BackgroundWorker or use asynchronous calls to do I/O and network requests

There is also a setting you can put in app.config that tells the runtime to not authenticate the assemblies with the certificate (this check can take a long time, especially cold starts):

<configuration>
  <runtime>
    <generatePublisherEvidence enabled="false"/> 
  </runtime>
</configuration>

Some more general tips are available on the MSDN site on Application Startup Time.

长梦不多时 2024-11-23 01:09:52

也许这个网站会对您有所帮助。它列出了在 Windows 登录之前(如果它是服务)或之后启动应用程序的一些选项。它们涉及一些注册表黑客攻击,您需要在卸载过程中撤消这些黑客攻击。

Maybe this site will be helpful to you. It lists some of the options you have for starting an application before (if it's a service) or after Windows login. They involve some registry hacking which you'll need to undo during uninstall.

忱杏 2024-11-23 01:09:52

使用regedit,在注册表中创建一个DWORD

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Serialize

名为 StartupDelayInMSec

默认值应设置为 0,但请仔细检查。

这使我的应用程序启动后的启动时间缩短了大约 10 秒。

注意:序列化密钥可能不存在。
您可以通过右键单击资源管理器并选择新建 -> 创建它。关键

Using regedit, Create a DWORD in the registry at

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Serialize

called StartupDelayInMSec.

Default value should be set to 0, but double check.

This cut about 10 seconds off for my application launch time after startup.

note: The Serialize Key may not exist.
You can create it by right-clicking on Explorer and selecting New -> Key

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文