Thread: Discussion: deal with time change event in win32 service program

  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,820
    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?

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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,829
    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, 08:55 AM
  2. Replies: 1
    Last Post: 01-24-2005, 02: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, 10:53 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM