How to use profiler on windows application

To optimize our applications we use Profilers.There are many profilers available on the web.
But miniprofiler is the good one and it’s not cost you any bucks.

I recently faced a situation where I have to check the memory cunsomption by my console application to further optimize it.

So I used an extended version of miniprofiler, [MiniProfiler.Windows]

Objective: Extends the fantastic MiniProfiler and adds functionality to make it easy to use in windows based applications (E.g. console applications)
STEP 1: First, install the Nuget package into your application

PM> Install-Package MiniProfiler.Windows

NOTE: If you get an error about not being able to add “System.Web” when installing the package, check that your application is set to run with target framework “.NET Framework 4” NOT “.NET Framework 4 Client Profile”!

STEP 2: Second, start profiling


STEP 3: put some MiniProfiler steps around your code

using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))
//Do some work, E.g. call methods..

STEP 4: Finally, stop and spit out the results formatted for debug/console friendly viewing

var friendlyString = ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings();

Or Finally, stop and spit out the structured MiniProfiler that was run for manipulation of more complicated results

var result = ConsoleProfiling.StopAndGetProfiler();
//You can now check the MiniProfiler result, such as these useful properties:

Please see the below simple example:

using System;
using System.Threading;
using MiniProfiler.Windows;
using StackExchange.Profiling;
namespace ConsoleApplicationSimpleExample
internal class Program
private static void Main()
//Start profiling
Console.WriteLine("Starting to call methods..");

using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))

//Stop profiling and show results

//Allow viewing of results
Console.WriteLine("... press 'Enter' to exit process ...");

private static void DoTheQuickWork()
using (StackExchange.Profiling.MiniProfiler.Current.Step("DoTheQuickWork"))
Console.WriteLine(" ... done quick work ... ");

private static void DoTheSlowWork()
using (StackExchange.Profiling.MiniProfiler.Current.Step("DoTheSlowWork"))
Console.WriteLine(" ... done slow work ... ");

NOTE: You may get some error while implementing it.So to solve plese check this.

For further reading please follow:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.