Use an Action delegate to time a method…

2011/09/21

I wanted an ability to be able to simply time methods and write to a log/trace sink and a very simple approach that I ended up using was to provide a method that takes an Action delegate which would be the method that is to be timed.

The following is what I came up with (this is my reminder…)

private static void TestMethod1()
{
    LoggingHelper.TimeThis("doing something", () =>
    {
        Console.WriteLine("This is the Real Method Body");
        Thread.Sleep(100);
    });
}

More Posts