سؤال

I didn't use NGen before but now I need to improve startup performance of my WPF application. As I understand the common case is to run ngen during application installation. But my application is used for internal company needs and doesn't have installer (it would just complicate things).

Are there any other ways to run ngen? What if I do it when application is started for the first time? Will I need administrator rights for that?

هل كانت مفيدة؟

المحلول

According to MSDN (first line under Remarks), you'll need administrative privileges to run ngen. It would probably be easier to package your application in a simple MSI, because I don't think you can elevate your privileges from inside the application to run ngen. You would have to alter the manifest file which would cause your app to require administrative privileges every time it is started.

نصائح أخرى

If your app targets .NET 4.5 or higher and runs on Windows 8 or higher, then you may be able to utilize Auto NGEN. Auto NGEN is a maintenance task that runs when the user machine is idle. The maintenance task automatically runs NGEN on "eligible" assemblies.

For your scenario, you would need to install your app into the GAC. Upon first launch of the app, .NET runtime generates a usage log and writes down your app assemblies. Auto NGEN task simply consumes these logs and runs NGEN for you. So, typically you would get an improved startup performance after maintenance task run is complete. (I think it typically runs 3 AM)

See this link for some info: http://eknowledger.wordpress.com/2012/05/04/clr-4-5-net-framework-kernel-improvements/

Note that, just like NGEN, installing assemblies to GAC require admin privileges. :) So you may prefer creating an installer and enable NGEN at install time as told in the above answer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top