Make .NET executable download faster the first time

I made a simple Windows Forms executable in C # (simple, I mean that it has about 20 methods, but this is just one window), focusing on the .NET Framework 2.0. When the application loads, it does nothing but the standard InitializeComponent(); in the constructor.

When you first open the application, it takes about 7 seconds to load into my Windows 8. Then it will take less than a second at the next moments when I open it.

On Windows XP, which I tried, it takes 30 seconds to load for the first time . A few of my friends, while testing the application, also complain that the download takes a lot of time for the first time (about 30 seconds). Then it runs faster (1 or 2 seconds).

I assume that this may be due to the fact that the .NET Framework has not yet been downloaded, so downloading them to your computer takes some time.

Have you ever experienced the same problem with .NET applications?
Do you have any clue why this is happening and how can I fix it?

EDIT - I see some people offer NGEN. However, if it is necessary to do this on all machines that will use the application, this may not be the solution for this. I want to publish my application to the general public from “regular users”, and this does not make sense if I demand that they make some additional materials for using my application. This is already so bad that we require the .NET Framework. My application should only be a standalone EXE without any dependencies (except the framework).

Thanks.

+4
source share
3 answers

You can try pre-creating your own image with NGEN, which .NET will use when your application loads.

Here you can find additional information - http://msdn.microsoft.com/en-GB/library/6t9t5wcf(v=vs.80).aspx

They are platform dependent and cannot be transferred normally, so you will need to do this on every machine you deploy to.

+6
source

This is most likely caused by the Just-In-Time CIL compilation. You can compile your code for the environment in which you work using NGen . However, you are likely to lose the agnostic of the .Net platform if you go down this route.

This MSDN blog post explains NGen's performance benefits in some detail, I suggest reading it.

Update the following comments

As Lloyd points out in his answer, if you give your users an installer, at this point you can run NGen for the environment in which the application is installed.

However, if NGen is not an option, then I would recommend running the application with an attached profiler. It can highlight any bottlenecks in your code. If you have singlets or expensive static initializers, they will be allocated as such and give you the opportunity to reorganize them.

There are many great .Net profiles here ( see this SO question ), I personally would recommend taking a look at dotTrace - they also offer a free trial period of a month, which may be all that is required for your application.

+5
source

[...] for the .NET Framework 2.0. When the application loads, it does nothing but the default InitializeComponent () value; in the constructor.

Actually, this is not so. The application also loads types, initializes static constructors, etc.

In most cases, when I have performance problems, I just use the profiler ... There can be a lot, and profiler is the easiest way to get some ideas. There are various options; I personally am a fan of Red-Gate profilers, and they have a trial version that you can use.

It should be noted that the way this happened has changed in the .NET Framework. If you cannot get performance in 2.0, I would just try a different framework. Of course, Windows XP can be a small problem ...

0
source

All Articles