["","windows~","27 Windows ","K,rtrwtysz+(CCY8*(CST~~}T~~.P979666997*/CE(B(CP55XS}T~~}T~~","NGEN"," optimizes startup time. With an installer class that automates NGEN precompilation, we improve Windows Forms startup time. The code must be run automatically at install time.","Steps."," First, your installer class will need to know lots of details about the runtime and use several commands. I list some steps to prepare for automating NGEN.exe in your C# application. ","Next: ","This is the command line you can type into the terminal or console to run NGEN.exe at any time on your computer.","Tip: ","It is the essential line that our installer class must use automatically to invoke NGEN.","Example command line","\n\n","[path to NGEN]","ngen.exe install ","[path to assembly]","assembly.exe","Module."," You need to use an installer module, add it to your assembly, and compile it. This installer module must know the full path of NGEN.exe and your assembly's name, which usually ends in .exe. These values can be found programmatically.","Go to the Project menu."," In the project menu, go to Add New Item and then select \"Installer Class\" from the list. Create NgenInstaller.cs. In my projects, I used this name for the installer class. ","Next: ","We show the method you must add to your installer class to make an installer module that runs NGEN.exe at install time.","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","Installer."," Here is the Install method that we need to put in the Installer Class. Here is most important part\u2014the Install method we need to add. It overrides the default Install method, and runs the important system commands to NGEN. ","NGEN installer class: C#","\n\nusing System.Collections;\nusing System.ComponentModel;\nusing System.Configuration.Install;\nusing System.Diagnostics;\nusing System.Runtime.InteropServices;\nusing System.IO;","\n\n/// <summary>\n/// This is run as a custom action by an MSI installer.\n/// It is used to call NGEN, which optimizes the assembly.\n/// </summary>\n","[RunInstaller(true)]\npublic partial class ","NgenInstaller"," : ","Installer","\n{\n public NgenInstaller()\n {\n InitializeComponent();\n }","\n\n /// <summary>\n /// An override function that is called when a MSI installer is run\n /// and the executable is set as a custom action to be run at install time.\n /// The native image generator (NGEN.exe) is called, which provides a\n /// startup performance boost on Windows Forms programs. It is helpful to\n /// comment out the NGEN code and see how the performance\n /// is affected.\n /// </summary>\n /// <param name=\"stateSaver\">No need to change this.</param>\n ","public override void ","Install","(IDictionary stateSaver)\n {\n base.Install(stateSaver);","\n\n // get the .NET runtime string, and add the ngen exe at the end.\n ","string runtimeStr = RuntimeEnvironment.GetRuntimeDirectory();\n string ngenStr = Path.Combine(runtimeStr, \"ngen.exe\");","\n\n // create a new process...\n ","Process process = new Process();\n process.StartInfo.FileName = ngenStr;","\n\n // get the assembly (exe) path and filename.\n ","string assemblyPath = Context.Parameters[\"assemblypath\"];","\n\n // add the argument to the filename as the assembly path.\n // Use quotes--important if there are spaces in the name.\n // Use the \"install\" verb and ngen.exe will compile all deps.\n ","process.","StartInfo.Arguments"," = \"install \\\"\" + assemblyPath + \"\\\"\";","\n\n // start ngen. it will do its magic.\n ","process.","Start","();\n process.","WaitForExit","();\n }\n}","MSI setup."," Here are the steps, from start to finish, you must take to make the installer class do its magic. It is clearly possible in other installers, but the instructions are different and I have no experience in that area.","Getting started."," Make a setup project. Go to File -> New Project, and make an MSI installation project. Add output files. Add the C# project output files under the Install custom action. ","Tip: ","This is accomplished through the VS GUI and just takes some exploration and trial and error.","Visual Studio ","visual-studio","Run the new setup.exe created."," Use Process Explorer to verify that no methods are JITted. Process Explorer has a JIT column that you can add, and if that number is zero when you run your program, the method worked. ","Process Explorer ","http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx","Results."," My programs with NGEN take about half as much time to start up, and use fewer cycles and a bit less memory. NGEN generates native images for an assembly exe, meaning that the JIT compiler doesn't need to run at startup. ","Note: ","The test program was precompiled with NGEN. It slightly improved startup time.","NGEN timings before and after: Windows Forms","\n\nBefore, no precompilation: ","0.2556 seconds","\nAfter, NGEN: ","0.2184 seconds"," [faster]","Summary."," We developed a NGEN installer class in the C# language. NGEN images are essentially native programs, and often about as fast as native programs, at least when starting up. The .NET Framework is still required. ","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","3679700504","data-ad-format","link","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509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