Friday, September 21, 2007

How to precompile method from MSIL to native code without invoking it

In order to precompile method without invoking it you should use System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod method.

Possible situation when this method is extremely necessary: You need to precompile huge assembly in separate thread during application delays and you can't use ngen.exe.

User always complain about lazy load of all screens in .NET applications. This lazy load is caused by JIT compilation...
For instance, you have fat (rich) client application with log-in screen. During log-in process you can pre-compile heavy assemblies in separate thread.

1 comment:

Sasha said...

A more realistic scenario is what the runtime does when you derive from CriticalFinalizerObject, or when you're in a constrained region.