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. About building a Windows service

About building a Windows service

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 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.
  • Z Offline
    Z Offline
    zhaopi
    wrote on last edited by
    #1

    I am about to implement a windows background service. I have succeeded to build the basic functions such as creating, stopping and deleting the service. The service is actually built basing on an infinite while loop (while(1)), if i put some simply operation like file processing in the while loop, it works fine~ when i put this line "doc. getdocumentlist(doclist, 9);" in, the program just stops there and cannot proceed to the codes below( this can be seen from the log file content). Can anybody explain this to me... void cService::EndlessLoop() { Output("EndlessLoop Start\n"); SYSTEMTIME Clock; CString Out; Cdocumentdb doc; // This endlessloop is killed by Windows when the service is stopped or shutdown while (1) { if (hTimer != 0) { LARGE_INTEGER Elapse; Elapse.QuadPart = -10000000; // 5 Seconds in 100 Nanoseconds resolution (negative=relative) BOOL Res = ::SetWaitableTimer(hTimer, &Elapse, 0, 0, 0, TRUE); if (Res) { DWORD Event = WaitForSingleObject(hTimer, 30000); // 30 seconds timeout // Event = (258=WAIT_TIMEOUT) (128=WAIT_ABANDONED) (0=WAIT_OBJECT_0) (0xFFFFFFFF=WAIT_FAILED) } } CArray doclist; **doc. getdocumentlist(doclist, 9);** ::GetLocalTime(&Clock); Out.Format("Timer %02d:%02d:%02d:%03d", Clock.wHour, Clock.wMinute, Clock.wSecond, Clock.wMilliseconds); Output(Out); }; }

    Z 1 Reply Last reply
    0
    • Z zhaopi

      I am about to implement a windows background service. I have succeeded to build the basic functions such as creating, stopping and deleting the service. The service is actually built basing on an infinite while loop (while(1)), if i put some simply operation like file processing in the while loop, it works fine~ when i put this line "doc. getdocumentlist(doclist, 9);" in, the program just stops there and cannot proceed to the codes below( this can be seen from the log file content). Can anybody explain this to me... void cService::EndlessLoop() { Output("EndlessLoop Start\n"); SYSTEMTIME Clock; CString Out; Cdocumentdb doc; // This endlessloop is killed by Windows when the service is stopped or shutdown while (1) { if (hTimer != 0) { LARGE_INTEGER Elapse; Elapse.QuadPart = -10000000; // 5 Seconds in 100 Nanoseconds resolution (negative=relative) BOOL Res = ::SetWaitableTimer(hTimer, &Elapse, 0, 0, 0, TRUE); if (Res) { DWORD Event = WaitForSingleObject(hTimer, 30000); // 30 seconds timeout // Event = (258=WAIT_TIMEOUT) (128=WAIT_ABANDONED) (0=WAIT_OBJECT_0) (0xFFFFFFFF=WAIT_FAILED) } } CArray doclist; **doc. getdocumentlist(doclist, 9);** ::GetLocalTime(&Clock); Out.Format("Timer %02d:%02d:%02d:%03d", Clock.wHour, Clock.wMinute, Clock.wSecond, Clock.wMilliseconds); Output(Out); }; }

      Z Offline
      Z Offline
      zhaopi
      wrote on last edited by
      #2

      sorry, forgot to say, what the "doc. getdocumentlist(doclist, 9);" is to retrieve some information from a database table...

      B 1 Reply Last reply
      0
      • Z zhaopi

        sorry, forgot to say, what the "doc. getdocumentlist(doclist, 9);" is to retrieve some information from a database table...

        B Offline
        B Offline
        Blake Miller
        wrote on last edited by
        #3

        Does your code work when it is NOT placed into a service? If that is true, then it could be a permissions issue. You might need to make sure the service runs under an account that has the proper privileges and security to access the database.

        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