ANTS Profiler™
How to profile a desktop application that hosts the .NET runtime
This article will explain how you can use ANTS Profiler 3 to profile either the performance or the memory of a native desktop application that hosts the .NET Common Language Runtime (CLR). Native or unmanaged applications can call .NET components using COM callable wrappers. (More details at http://msdn2.microsoft.com/en-us/library/ms973802.aspx.)
Typical examples of this type of development are .NET Visual Studio Add-ins, managed code extensions for Word and Excel, and managed code add-ins for Outlook.
We will see that profiling these types of applications is just as straightforward with ANTS Profiler as profiling standard .NET applications.
Setting up the profiler
We will work through setting up an ANTS Profiler project to profile the performance of a Word 2003 document that uses managed extensions. On the first step of the project wizard we select Performance profiler – Detailed Mode. For the second screen we choose .NET desktop application (although we know that Word 2003 is not a .NET app).
On the second screen, we need to enter the file path for WINWORD.EXE for the executable path, and the full path of the Word document that we want to profile in the Start options/Arguments window.

We will leave the final screen on the default selection of Only .NET methods that have source code, as we have a debug build of our Visual Studio 2005 Word project. We are now ready to start profiling.
Starting the profiler
We now start profiling by hitting Finish and accepting the dialog that asks whether we want to profile WINWORD.EXE. We are presented with a dialog that warns us that WINWORD.EXE is not a .NET application. At this point we continue, as we know that WINWORD will be loading the .NET Framework to allow it to run the managed extensions.
Profiling now commences, and we should see our Word document appear. We also note that the status message at the bottom of ANTS Profiler reads Profiling performance of WINWORD.EXE.
Getting results
Once we are up and running with profiling, we can get a set of performance results by taking a snapshot. Once we are done, we can close down the Word document, to generate a final set of results and stop the profiling session. We can investigate the results in exactly the same fashion as we would any .NET application. This will quickly allow us to spot any big bottlenecks or areas of inefficient code.
Other applications
Exactly the same approach will work with all other hosting applications. For example, to profile a Visual Studio .NET add-in, the key step is to enter the full path to devenv.exe as the .NET application that you want to profile (typically C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe for VS.NET 2005).
Conclusion
Hopefully, this short article will get you going with optimizing the performance and memory usage of your .NET hosting applications.





