Results 1 to 3 of 3

Thread: Looping Efficiency - Is There A Better Way?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    12

    Question Looping Efficiency - Is There A Better Way?

    Newbie Programmer here looking for advice: I have a small app that checks a sorted array with a date/time field as a "trigger" (only 3 records entered to test).

    Thing is, while this "check loop" is running it may be too simple to be practical - the app eats up CPU cycles while just "checking" for the next trigger time, which could be set for hours or days away.

    Is there a more efficient way to program this? Like a "sleep time" function or a better known method for "checking" only once a minute or so? (Even "high level" advice would be appreciated.) Thanks!

    ex:

    Code:
    X = 0
    Do While X <> 3
       Y = X
       Do While Y = X
          If Date.Now > TableData(X).TriggerDateTime Then
              [Action Code]
              X = X + 1
          End If
       Loop
    Loop
    ---------------
    ENV
    mailto:[email protected]

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Looping Efficiency - Is There A Better Way?

    I have no idea what language nor OS you are using. But if it is on Windows, and you are using a language that can use API calls, then you can call Sleep() for as long as you want. That pauses your whole app, so be aware of that. But if that doesn't do anything, then that should be sufficient.


    - ØØ -

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    12

    Re: Looping Efficiency - Is There A Better Way?

    Just using VB.NET. I wouldn't want it to "hang" the rest of my application, but I just notice that while this is running (and waiting) my CPU is at 50% usage...and all it's doing is looping/waiting...

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