#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Running a C# app at set intervals.


    I wasn't sure where to put this, but seeing as it involves a C# app, I thought I'd put it here.

    I used to run a windows dedicated server, but had to downgrade to shared hosting.

    A while back I coded a C# app. The app was fairly simple, it would load a webpage every 3 hours, but it would send a unique key as a query string each time. This was made up of a shared passcode plus the date & hour hashed together as an MD5 string.

    It was a simple security feature making the URL unique every time so only the app could load the page.

    Anyway, I was using windows scheduled task to run the app every 3 hours, 24/7, but with shared hosting I can't do that now unless I run the app from home, which just isn't viable.

    Does anyone know of a service that will let you upload and run a .bat or .exe file periodically?


    Thanks
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    So is it relatively easy for you to do something using this
    Code:
    while ( true ) {
        ULONGLONG start = GetTickCount64();
        // do all your work here
        ULONGLONG end = GetTickCount64();
        ULONGLONG elapsed = end - start;
        Sleep( 3 * 60 * 60 * 1000 - elapsed );
    }
    You don't seem to have anything else to do in your app, if it was just exiting and waiting for the scheduler to kick it off again.

    So you may as well sleep until the next 3hr mark, allowing for time taken already.
    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

IMN logo majestic logo threadwatch logo seochat tools logo