Click here to Skip to main content
Licence CPOL
First Posted 4 Jun 2009
Views 8,980
Downloads 150
Bookmarked 12 times

Ngen Installer

By | 4 Jun 2009 | Article
Provides GUI for selecting an EXE using Ngen.

Introduction

This small application allows the user to select an EXE from a dialog by which it will use the Native Image Generator (Ngen.exe).

As most who use Ngen know, it is a command line tool which is not very intuitive. I got tired of typing the commands in, and created this app to simply select the EXE.

Using the code

The code is as easy as it gets. You select the button and choose your program's EXE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
namespace NgenInstaller
{
    public partial class MainForm : Form
    {
        private Process ngenProcess = new Process();
        private string runtimeStr = 
           RuntimeEnvironment.GetRuntimeDirectory();
        private string ngenStr;
        public MainForm()
        {
            InitializeComponent();
            ngenStr = Path.Combine(runtimeStr, "ngen.exe");
        }
        private void btnSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "EXE files (*.exe)|*.exe";
            ofd.FilterIndex = 1;
            ofd.RestoreDirectory = true;
            DialogResult dr = DialogResult.OK;
            if (ofd.ShowDialog() == dr)
            {
                ngenProcess.StartInfo.UseShellExecute = false;
                ngenProcess.StartInfo.FileName = ngenStr;
                ngenProcess.StartInfo.Arguments = 
                  string.Format("install \"{0}\"", ofd.FileName);
                ngenProcess.Start();
                ngenProcess.WaitForExit();
            }
        }
    }
}

Points of interest

The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly.

For more information, see: http://msdn.microsoft.com/en-us/library/6t9t5wcf(VS.80).aspx.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

John Grove



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberZhekov22:53 14 Jun '09  
GeneralRe: My vote of 1 PinmemberJohn Grove14:20 16 Jun '09  
GeneralMy vote of 2 PinmemberHei-Tech2:07 10 Jun '09  
GeneralRe: My vote of 2 PinmemberJohn Grove2:55 10 Jun '09  
GeneralMy vote of 1 PinmemberOlivier Fermy20:47 8 Jun '09  
GeneralRe: My vote of 1 PinmemberJohn Grove3:55 9 Jun '09  
GeneralMy vote of 1 PinmemberIzzet Kerem Kusmezer2:56 5 Jun '09  
GeneralRe: My vote of 1 [modified] PinmemberJohn Grove3:10 5 Jun '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 4 Jun 2009
Article Copyright 2009 by John Grove
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid