none
Compile all assembles at start of the application. RRS feed

  • Question

  • Hello.

    Could anyone tell me, how can I force JIT-compiler compile all assembles in the solution at start of the application (not at first call methods from assembly)? I used ngen.exe to compile all assembles into native code after installation of the application. But i suspect that I can compile to native code more simple.
    My application work with delay about 0.5-1 sec. when it call methods of  ancillary assembly first time.  I want to remove this delay and i don't wont to use ngen.exe.

    Thanks

    P.S. sorry for my English. I'm not a native English speaker
    Wednesday, February 4, 2009 6:26 AM

Answers

  • Actually you can force the jit compiler to compile additional methods using System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod. this article on code project shows how to use it. ngen comes with the FrameWork and therefore is available on any client, even visual studio uses it in its installer. I see no problem in using it, especially since you say you take a big hit from this one specific assembly I'd rather take it once with ngen at installation time then every time the app is started.
    • Marked as answer by Zhi-Xin Ye Monday, February 9, 2009 9:20 AM
    Wednesday, February 4, 2009 2:24 PM

All replies

  • The JIT compiler will only ever compile methods that are called.  You can't force it to compile code you'll call later.  That ought to be a good incentive to use Ngen.
    Hans Passant.
    Wednesday, February 4, 2009 12:15 PM
    Moderator

  • I have rather big delay when JIT compiler compile addition assembly. This time is critical.  using Ngen isn't a good solution. (ngen can be used, but it is not good decision to use additional utilities, i think). I fix this problem by calling methods from additional assembly at start of application. But it's back-door solution.
    Wednesday, February 4, 2009 12:54 PM
  • Actually you can force the jit compiler to compile additional methods using System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod. this article on code project shows how to use it. ngen comes with the FrameWork and therefore is available on any client, even visual studio uses it in its installer. I see no problem in using it, especially since you say you take a big hit from this one specific assembly I'd rather take it once with ngen at installation time then every time the app is started.
    • Marked as answer by Zhi-Xin Ye Monday, February 9, 2009 9:20 AM
    Wednesday, February 4, 2009 2:24 PM
  • Ray M_ : Thank you, But i'm very surprised that .net framework haven't any method to compile assembly, like a Compile(AssemblyName).
    And Thank you again.
    Tuesday, February 10, 2009 6:47 AM
  • My customer don't like to see "Dos-ngen-windows"  during installation. That's why I have to find another way.
    Tuesday, February 10, 2009 10:03 AM
  • That's what the .NET Runtime Optimization service is for.  Use it with ngen.exe install /queue
    Hans Passant.
    Tuesday, February 10, 2009 10:33 AM
    Moderator
  • Thanks all. Your answers are usefull.
    Thursday, February 12, 2009 11:51 AM