-
Datetime Q
Just a quickie
I am trying to see how long it takes to do something
the way I am checking to see if the time elapsed is less then a second is this, but it never seems to exit the loop:
Code:
while (DateTime.Now.Millisecond < 1000)
{
this.lstMsgs.Items.Add(DateTime.Now.Millisecond.ToString());
}
this.lstMsgs.Items.Add("1 sec up");
it never seems to exit the loop.
any ideas?
-
Re: Datetime Q
umm you're not understanding this correctly
DateTime.Now returns the current time, so you're basically saying while the current time's milliseconds is less than 1000 repeat the loop.
I would just use the system tickcount (the value is in milliseconds... usually means the number of milliseconds since the system was rebooted)
int startTick = Environment.TickCount;
do
{
//stuff here
}while (Environment.TickCount - startTick <1000)
you could also use a TimeSpan object, or try using DateTime's Subtract() method, but I think what I just said above is fairly efficient.
-
Re: Datetime Q
oh yeh, of course ...
thanks Mr.Polite ;)