It seems like there are a lot of ways to calculate time spans in c#. I am wondering which one is fastest and by that I simply means requires the least amount of processing. Let me throw out an example to illustrate exactly what I am trying to do.
private const int timeBetweenEvents = 250; //delay ms
DateTime nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0, 0, timeBetweenEvents));
...
while(true)
{
if (DateTime.Now > nextUpdate)
{
// do something
nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0, 0, timeBetweenEvents));
}
// ...
// do some other stuff
// ...
}
another option...
private const int timeBetweenEvents = 250; //delay ms
TimeSpan nextUpdate = DateTime.Now.TimeOfDay.Add(new TimeSpan(0,0,0,timeBetweenEvents));
...
while(true)
{
if (DateTime.Now.TimeOfDay > nextUpdate)
{
// do something
nextUpdate = DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, 0, timeBetweenEvents));
}
// ...
// do some other stuff
// ...
}
I have also seen similar things by doing subtractions using System.Environment.TickCount. So what is the bst way to do this?