Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Design Question

Design Question

Scheduled Pinned Locked Moved C / C++ / MFC
databasecomdesignbusinessquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tony Fontenot
    wrote on last edited by
    #1

    I am writing a console program that will go to a database at certian intervals. Basically, I am trying to implement an automated email system for expired records. My question comes when trying to decide between using a Timer or just have the program use Sleep(). So I want the program to check the database every x number of minutes (probally every hour) and see if anything needs to be sent. My restrictions are that it has to be able to run on win98 and higher. Any suggestions. Right now I am leaning toward Sleep(), but I am not sure if that is a viable business app solution. Thanks in advance, *********************** Tony Fontenot Recreational Solutions tony@recsolutions.com ***********************

    N P 2 Replies Last reply
    0
    • T Tony Fontenot

      I am writing a console program that will go to a database at certian intervals. Basically, I am trying to implement an automated email system for expired records. My question comes when trying to decide between using a Timer or just have the program use Sleep(). So I want the program to check the database every x number of minutes (probally every hour) and see if anything needs to be sent. My restrictions are that it has to be able to run on win98 and higher. Any suggestions. Right now I am leaning toward Sleep(), but I am not sure if that is a viable business app solution. Thanks in advance, *********************** Tony Fontenot Recreational Solutions tony@recsolutions.com ***********************

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      If you are depending on executing something every minute, I would not rely on Sleep() since you don't know how long your database queries will take (unless you do some math to calculate the remaining sleep time, but still there are some things to consider). The query time might differ from call to call. If that minute is allowed to be fuzzy, then, a Sleep() might be the way to go. Consider how you want the program to behave if a database query takes over (or about) a minute. Consider that timers are system resources, and there might be none available at times. Hmmm... well, can't think of anything more for the moment.

      1 Reply Last reply
      0
      • T Tony Fontenot

        I am writing a console program that will go to a database at certian intervals. Basically, I am trying to implement an automated email system for expired records. My question comes when trying to decide between using a Timer or just have the program use Sleep(). So I want the program to check the database every x number of minutes (probally every hour) and see if anything needs to be sent. My restrictions are that it has to be able to run on win98 and higher. Any suggestions. Right now I am leaning toward Sleep(), but I am not sure if that is a viable business app solution. Thanks in advance, *********************** Tony Fontenot Recreational Solutions tony@recsolutions.com ***********************

        P Offline
        P Offline
        Paul M Watt
        wrote on last edited by
        #3

        I would use a waitable timer. Because it will block your program while you are waiting, but if you expand your program in the future, you will have the ability to wake that thread up before the timer expires. With Sleep, your program will block for the same amount of time and this cannot be changed at runtime. Here is an example from MSDN of how to use a waitable timer.

        #include #include int main()
        {
        HANDLE hTimer = NULL;
        LARGE_INTEGER liDueTime;

        liDueTime.QuadPart=-100000000;
        
        // Create a waitable timer.
        hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
        if (!hTimer)
        {
            printf("CreateWaitableTimer failed (%d)\\n", GetLastError());
            return 1;
        }
        
        printf("Waiting for 10 seconds...\\n");
        
        // Set a timer to wait for 10 seconds.
        if (!SetWaitableTimer(
            hTimer, &liDueTime, 0, NULL, NULL, 0))
        {
            printf("SetWaitableTimer failed (%d)\\n", GetLastError());
            return 2;
        }
        
        // Wait for the timer.
        
        if (WaitForSingleObject(hTimer, INFINITE) != WAIT\_OBJECT\_0)
            printf("WaitForSingleObject failed (%d)\\n", GetLastError());
        else printf("Timer was signaled.\\n");
        
        return 0;
        

        }


        Build a man a fire, and he will be warm for a day
        Light a man on fire, and he will be warm for the rest of his life!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups