Results 1 to 3 of 3

Thread: Datetime Q

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Datetime Q

    oh yeh, of course ...

    thanks Mr.Polite

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width