A
A
Apfel2013-12-24 15:22:13
.NET
Apfel, 2013-12-24 15:22:13

C# and ngen.exe: How to translate to native code?

I will say right away: I do not need to abandon the .NET platform =)
And the question is not about how to get framework-independent code.
So, there is a weighty business application in C # using Windows Forms.
The application has dozens of different dialog boxes for different needs, tray event notifications and context menus.
By good tradition, all this is translated into machine code at runtime and takes time.
The first opening of a dialog box, the appearance of a context menu, navigation through the top menu - all this takes time and quite noticeably freezes.
Of course, after active work with the application, the slowdowns disappear.
But this is repeated over and over again.
Question:
I read that using the ngen utility, you can translate the bytecode into the machine code on the target machine in advance. I searched on MSDN, found a couple of examples, including looking through ngen /?
Tried to apply to assembly.
The utility works, but there is no result: it works as it used to, with a slow start and slowdown during the first work.
And now the question is: how to use it correctly in order to eventually get the correct assembly on the target machine?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
andreycha, 2013-12-28
@Apfel

1) ngen must be applied to the main exe file and all libraries of your program (third-party libraries are optional).
2) ngen is used on the end user's computer (for example, as suggested above, during installation). Running ngen on your machine and then copying the application to the user won't work that way.
Well, to make sure that really native assemblies are loaded while the application is running, use Fuslogvw.exe from Visual Studio, the documentation is on the MSDN website.

I
Ilya Evseev, 2013-12-25
@IlyaEvseev

Alternative to ngen: www.mono-project.com/AOT

M
maxaon, 2013-12-24
@maxaon

Most likely you applied the utility incorrectly. It is usually launched during installation and puts a ready-made and deployed assembly into the cache. And if you run on the debug version, then probably the cache will not be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question