Discussion: deal with time change event in win32 service program

This is a discussion on Discussion: deal with time change event in win32 service program within the Windows Programming forums, part of the Platform Specific Boards category; In my program, I want to get local time in real time and if the time fits with the setting ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    42

    Discussion: deal with time change event in win32 service program

    In my program, I want to get local time in real time and if the time fits with the setting of my program, another thread will wake up ,do some operations and sleep. After some hours, the time fit with the setting again the thread is waked up again and......

    I don't want to use loop to get current time, are there any good idea about this situation?


    thanks a lot

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Making a virus are we?
    Woop?

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    si basically, your program would be running in the background the whole time the computer's on?
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Use SetTimer() to send you a WM_TIMER message when the timer expires.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Waitable timers are ideal for this task. Your lazy thread could look something like this:
    Code:
    HANDLE hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
    
    while (TRUE)
    {
    	/* Set liDueTime to the time you want the timer to trigger. */
    
    	SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, FALSE);
    	WaitForSingleObject(hTimer, INFINITE);
    
    
    	/* Do work here. */
    }
    Waitable timers can even wake your computer up from suspend mode (if supported).

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    42
    Thanks, anonytmouse. After I posted this thread, I read some chapters of jeffrey's "advanced windows programming" again and then...... the answer is in your thread.

    to prog-bman: not a virus, just a common win32 service program

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    Why not use the OS scheduler to just say when you want your main program to run?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    42
    To Salem: I'm sorry, I don't understand the meaning of your thread. Would you mind explain it in detail?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334

  10. #10
    Registered User
    Join Date
    Jun 2004
    Posts
    42
    Oh, I see..... but I just want some thread in my program to be waked up in some time interval. Task scheduler does not afford this mechanism. Anyway, thanks

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    Oh please, you can set multiple events for the same program

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Can you use the task scheduler to wake individual threads within an application? I don't use it, so am no expert. As I suggested already, I'd use one of the various OS supplied timer functions.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  2. Replies: 1
    Last Post: 01-24-2005, 01:07 PM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  4. windows time change event
    By Nate in forum Windows Programming
    Replies: 5
    Last Post: 11-19-2002, 09:53 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21