System.Timers.Timer vs System.Threading.Timer

This article offers a fairly comprehensive explanation: “Comparing the Timer Classes in the .NET Framework Class Library” – also available as a .chm file The specific difference appears to be that System.Timers.Timer is geared towards multithreaded applications and is therefore thread-safe via its SynchronizationObject property, whereas System.Threading.Timer is ironically not thread-safe out-of-the-box. I don’t believe … Read more

Calculate the execution time of a method

Stopwatch is designed for this purpose and is one of the best ways to measure time execution in .NET. var watch = System.Diagnostics.Stopwatch.StartNew(); // the code that you want to measure comes here watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Do not use DateTime to measure time execution in .NET. UPDATE: As pointed out by @series0ne in … Read more