Thread: timeSetEvent

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    timeSetEvent

    When using timeSetEvent with a callback function, how does the callback function actually get called? If my app is busy in another function will that function be interrupted to run the timer function, or will it run at the same time, or will it run at the end of that function, etc? The PC I'm running on is quad core and I read that timeSetEvent uses threads to perform it's magic.

    Secondly, if I set timeSetEvent to 1ms and the function takes longer than 1ms, will it be called again immediately (interrupting the current one or running two copies of the code), or wait until it returns the first time returns before calling again?

    The documentation doesn't say how it works other than "It uses threads".

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    timeSetEvent

    The callback function will be called each time the specified timeout occurs.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Mole42 View Post
    When using timeSetEvent with a callback function, how does the callback function actually get called? If my app is busy in another function will that function be interrupted to run the timer function,or will it run at the same time, or will it run at the end of that function, etc?
    AFAIK the timer event will occur after your app has finished.

    Quote Originally Posted by Mole42 View Post
    Secondly, if I set timeSetEvent to 1ms and the function takes longer than 1ms, will it be called again immediately (interrupting the current one or running two copies of the code), or wait until it returns the first time returns before calling again?
    Most likely you will get a delay followed by a series of timer messages because the thread executing the multi media timer calls is not considered to be _THE_ highest priority. [assuming you have used the period flag and not the once off flag in settign up the timer].

    AFAIK there is no way to increase this threads priority.

    Even if you reset the PIC to a 1 msec resolution using timeBeginPeriod() I doubt that you will get a 1msec resolution if the target machine is under any load (as the minimun resolution is usually 15-50 msec depending on OS/CPU).

    Changing the PIC resolution will increase the responsiveness but this can also reduce system performance by increasing overhead (system tasks/function running more frequently).

    I have managed to get a sub 1 msec timer on CE using a filter driver however (but that was a lot of work).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    26
    Many thanks novacain, you answered the question brilliantly, much better than just quoting the msdn to me which I already read before posting (and stated in my first post).

    This board should have a "Thank this user" button.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. timeSetEvent problem
    By likeregularchic in forum Windows Programming
    Replies: 6
    Last Post: 09-10-2005, 07:36 PM
  2. compiling mingw to enable timeSetEvent
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2005, 06:00 PM