Many of the .NET APIs take time intervals as their parameters, and it usually is in milliseconds.

For example:


From your primary school days, you will remember 1000 milliseconds make one second.

This is fine for simple examples but what if you want your thread to sleep for 30 minutes.

Many people would do it like this:

Thread.Sleep(1000 * 60 * 30)

Which is perfectly correct, but it is difficult to read. You have to spend some mental cycles to find out what is happening here.

A far easier, and clearer way to write the same code is to use the TimeSpan class.

// Sleep for 30 minutes

In addition to minutes you also have methods that operate with ticks, milliseconds, seconds, hours and even days.

This makes the code much easier to understand and maintain.

Happy hacking!