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. How to use SYSTEM function for specified time

How to use SYSTEM function for specified time

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorial
7 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.
  • M Offline
    M Offline
    MKC002
    wrote on last edited by
    #1

    how to use system API for given time some times a when i call system api, my computer hangs and i need to reboot can i use for given time

    S L 2 Replies Last reply
    0
    • M MKC002

      how to use system API for given time some times a when i call system api, my computer hangs and i need to reboot can i use for given time

      S Offline
      S Offline
      Software_Developer
      wrote on last edited by
      #2

      The API function [SetTimer ] executes a function every x milliseconds or any given time. MFC version [here]. Console example: The following console program works like this: It sets a timer using SetTimer then loops in a message loop. The message loop receives and processes WM_TIMER messages and the timer callback also is called for each time interval. Simply put the stuff you want done in the TimerProc() function.

      #define STRICT 1
      #include #include VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
      {
      //put the stuff you want done in here

      cout << "Doing stuff Time: " << dwTime << '\n';
      cout << "--------------------------------------------------\n" ;
      cout.flush();
      }

      int main(int argc, char *argv[], char *envp[])
      {
      int Counter=0;
      int usage_Time_millisec=500;
      MSG Msg;

      UINT TimerId = SetTimer(NULL, 0, usage\_Time\_millisec, &TimerProc); //bind TimerProc() to SetTimer() 
      
      cout << "TimerId: " << TimerId << '\\n';
      

      if (!TimerId) return 16;

      while (GetMessage(&Msg, NULL, 0, 0))
      {
      ++Counter;
      if (Msg.message == WM_TIMER)
      cout << "Doing stuff Counter: " << Counter << "; timer message\n";
      else
      cout << "Doing stuff Counter: " << Counter << "; message: " << Msg.message << '\n';
      DispatchMessage(&Msg);
      }

      KillTimer(NULL, TimerId);

      return 0;

      }

      1 Reply Last reply
      0
      • M MKC002

        how to use system API for given time some times a when i call system api, my computer hangs and i need to reboot can i use for given time

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        MKC002 wrote:

        how to use system API for given time

        What exactly do you mean by this; which API and what time?

        MKC002 wrote:

        some times a when i call system api, my computer hangs and i need to reboot

        Perhaps if you show an extract of the code that does this we may be able to help.

        MKC002 wrote:

        can i use for given time

        Use what and for what time - time of day, time interval, ...?

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        M 1 Reply Last reply
        0
        • L Lost User

          MKC002 wrote:

          how to use system API for given time

          What exactly do you mean by this; which API and what time?

          MKC002 wrote:

          some times a when i call system api, my computer hangs and i need to reboot

          Perhaps if you show an extract of the code that does this we may be able to help.

          MKC002 wrote:

          can i use for given time

          Use what and for what time - time of day, time interval, ...?

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          M Offline
          M Offline
          MKC002
          wrote on last edited by
          #4

          our server maintains large amount of data. Everyday new files/folders created on it. A serevice set some special properties for files/folders. One service checkes if some property does not exist in file/folder then move the file to another location for further processing. Here one service call GetFileAttributes and GetVolumeInformation for disk where file will be move. From this function we get volume label and other information to store in database. Sometimes system hangs and i need to reboot. I noticed system hangs due to GetVolumeInformation. So, can i set time limit for this function. If after given time i dont get volume label then move the file to another disk.

          L 1 Reply Last reply
          0
          • M MKC002

            our server maintains large amount of data. Everyday new files/folders created on it. A serevice set some special properties for files/folders. One service checkes if some property does not exist in file/folder then move the file to another location for further processing. Here one service call GetFileAttributes and GetVolumeInformation for disk where file will be move. From this function we get volume label and other information to store in database. Sometimes system hangs and i need to reboot. I noticed system hangs due to GetVolumeInformation. So, can i set time limit for this function. If after given time i dont get volume label then move the file to another disk.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            It's more important to discover why the system hangs on this function; perhaps it is trying to access a network disk and you are having network problems, or the drive is failing. You could also move this code into a background thread and then kill it after a fixed time interval from your main thread.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            M 1 Reply Last reply
            0
            • L Lost User

              It's more important to discover why the system hangs on this function; perhaps it is trying to access a network disk and you are having network problems, or the drive is failing. You could also move this code into a background thread and then kill it after a fixed time interval from your main thread.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              M Offline
              M Offline
              MKC002
              wrote on last edited by
              #6

              Thanks for your reply. To play with thread is little difficult. Please give any link to kill thread which is safe and does not result in any type of crash.

              L 1 Reply Last reply
              0
              • M MKC002

                Thanks for your reply. To play with thread is little difficult. Please give any link to kill thread which is safe and does not result in any type of crash.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                MKC002 wrote:

                Please give any link to kill thread which is safe and does not result in any type of crash.

                You do realise what you are asking! How can I possibly know what code could be added to your program that will not crash it, even if I could be bothered to go and look for such a link? You are the developer it's up to you to do the work.

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                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