02.07.2013 Views

.NET Interview Questions 4 th Edition By Shivprasad ... - A2Z Dotnet

.NET Interview Questions 4 th Edition By Shivprasad ... - A2Z Dotnet

.NET Interview Questions 4 th Edition By Shivprasad ... - A2Z Dotnet

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• You should have administrative privilege for running Ngen.exe.<br />

• While <strong>th</strong>is can fasten, your application startup times as <strong>th</strong>e code is statically compiled<br />

but it can be somewhat slower <strong>th</strong>an <strong>th</strong>e code generated dynamically by <strong>th</strong>e JIT<br />

compiler. Therefore, you need to compare how <strong>th</strong>e whole application performance<br />

wi<strong>th</strong> Ngen.exe and wi<strong>th</strong> out it.<br />

To run Ngen.exe, use <strong>th</strong>e following command line.<br />

ngen.exe install <br />

This will synchronously precompile <strong>th</strong>e specified assembly and all of its dependencies. The<br />

generated native images are stored in <strong>th</strong>e native image cache.<br />

In .<strong>NET</strong> Framework 2.0 <strong>th</strong>ere is a service (.<strong>NET</strong> Runtime Optimization Service) which can<br />

precompile managed assemblies in <strong>th</strong>e background. You can schedule your assemblies to be<br />

precompiled asynchronously by queuing <strong>th</strong>em up wi<strong>th</strong> <strong>th</strong>e NGEN Service. Use <strong>th</strong>e following<br />

command line.<br />

Ngen.exe install /queue :<br />

Assemblies, which are critical to your application’s start up time, should be precompiled ei<strong>th</strong>er<br />

synchronously or asynchronously wi<strong>th</strong> priority 1. Priority 1 and 2 assemblies are precompiled<br />

aggressively while Priority 3 assemblies are only precompiled during machine idle-time.<br />

Synchronously precompiling your critical assemblies guarantees <strong>th</strong>at <strong>th</strong>e native images will be<br />

available prior to <strong>th</strong>e first time your end user launches <strong>th</strong>e application but increases <strong>th</strong>e time taken<br />

to run your application's set up program.<br />

You can uninstall an assembly and its dependencies (if no o<strong>th</strong>er assemblies are dependent on<br />

<strong>th</strong>em) from <strong>th</strong>e native image cache by running <strong>th</strong>e following command.<br />

ngen.exe uninstall <br />

Native images created using Ngen.exe cannot be deployed; instead, <strong>th</strong>ey need to be created on <strong>th</strong>e<br />

end user's machine. These commands <strong>th</strong>erefore need to be issued as part of <strong>th</strong>e application's setup<br />

program. Visual Studio .<strong>NET</strong> can be used to implement <strong>th</strong>is behavior by defining custom actions<br />

in a Microsoft Installer (MSI) package.<br />

Note:- One of <strong>th</strong>e <strong>th</strong>ings <strong>th</strong>e interviewer will expect to be answered is<br />

what scenario will use a Native Image generator. Best is to say <strong>th</strong>at we<br />

first need to test <strong>th</strong>e application performance wi<strong>th</strong> Native Image and<br />

wi<strong>th</strong> out it and <strong>th</strong>en make a decision. If we see <strong>th</strong>at we have<br />

considerable performance difference we can <strong>th</strong>en use native image<br />

generator.<br />

(A) If we have two version of same assembly in GAC how do we make<br />

a choice?<br />

Note:- We really want to explain <strong>th</strong>is in dep<strong>th</strong> for two reasons. First<br />

we have seen <strong>th</strong>is question been frequently asked and second it’s of<br />

real practical importance. So let’s try to get <strong>th</strong>is fundamental not in<br />

our brain but in our heart.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!