开发者

How to optimize WPF app launch on Windows startup

开发者 https://www.devze.com 2023-03-13 10:55 出处:网络
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

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开发者_JS百科 reduce its startup time? Do I have any other choice than to code it natively? Thanks.


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.


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.


I like the Performance Tips of the wpftutorial.net much.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消