Click here to Skip to main content
15,506,757 members
Articles / Programming Languages / C#
Article
Posted 4 Jun 2009

Stats

31.2K views
840 downloads
13 bookmarked

Ngen Installer

Rate me:
Please Sign up or sign in to vote.
2.89/5 (8 votes)
4 Jun 2009CPOL
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.

C#
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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionNgen has lots of options! Pin
Behzad Sedighzadeh12-Oct-15 10:46
Behzad Sedighzadeh12-Oct-15 10:46 
So add options to your application. This makes it useful and improves it's rank Smile | :)
Behzad

GeneralMy vote of 1 Pin
Zhekov14-Jun-09 23:53
Zhekov14-Jun-09 23:53 
GeneralRe: My vote of 1 Pin
John Grove16-Jun-09 15:20
John Grove16-Jun-09 15:20 
GeneralMy vote of 2 Pin
Hei-Tech10-Jun-09 3:07
Hei-Tech10-Jun-09 3:07 
GeneralRe: My vote of 2 Pin
John Grove10-Jun-09 3:55
John Grove10-Jun-09 3:55 
GeneralMy vote of 1 Pin
Olivier Fermy8-Jun-09 21:47
Olivier Fermy8-Jun-09 21:47 
GeneralRe: My vote of 1 Pin
John Grove9-Jun-09 4:55
John Grove9-Jun-09 4:55 
GeneralMy vote of 1 Pin
Izzet Kerem Kusmezer5-Jun-09 3:56
Izzet Kerem Kusmezer5-Jun-09 3:56 
GeneralRe: My vote of 1 [modified] Pin
John Grove5-Jun-09 4:10
John Grove5-Jun-09 4:10 

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

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