HomeGenie Forum

General Category => Troubleshooting and Support => Topic started by: kevinvinv on February 15, 2016, 03:37:02 AM

Title: launching a program at specific times
Post by: kevinvinv on February 15, 2016, 03:37:02 AM
Hello,

I have a short C# program that I want to run every day at 10pm and 11pm.   How do I best do this?  Is there something that gets put in the "Startup Code" area then for this?

Thanks!
Title: Re: launching a program at specific times
Post by: bkenobi on February 15, 2016, 04:32:57 PM
You would check IsScheduling to trigger your code.

http://genielabs.github.io/HomeGenie/api/ape/a00010.html#ab6cf118ce821fc199ab6ce68a1eb9a8b (http://genielabs.github.io/HomeGenie/api/ape/a00010.html#ab6cf118ce821fc199ab6ce68a1eb9a8b)

You can use the Scheduled ON/OFF APP as a guide as it basically uses this approach to turn on/off modules.  Simplest would be to copy that code and switch the module on/off section with your code and use the crontab formatted string for your run times.
Title: Re: launching a program at specific times
Post by: kevinvinv on February 16, 2016, 05:12:01 AM
OK Thanks.

So here is what I have now:


while (Program.IsEnabled)
{
     
    var scheduleOff = "00,02 1,3 * * *";    // shut off lights that should be off at 1:00,  1:02 and 3:00 and 3:02

    if (Scheduler.IsScheduling(scheduleOff))
    {
      Program.Notify("Reseting the House", "Now");
      Program.ApiCall("HomeAutomation.X10/B/Control.AllLightsOff");
      Program.ApiCall("HomeAutomation.X10/E/Control.AllLightsOff");
    }

    //return false;

  var pause = (60 - DateTime.Now.Second);   // dont keep repeating this over and over for the entire minute
  Pause(pause);

};



The question I have is this:   Some programs I see end with a Program.GoBackground() command...    can you comment on what this does and when one needs to use it?

Thanks!
Title: Re: launching a program at specific times
Post by: bkenobi on February 16, 2016, 04:23:00 PM
I add GoBackground to all of my programs that are constantly running.  The documentation says you should use it with any program that is constantly looping.  Gene said it helps free resources as I recall.

http://genielabs.github.io/HomeGenie/api/ape/a00009.html#a73aaf7bc607c946fdd354a481262560a (http://genielabs.github.io/HomeGenie/api/ape/a00009.html#a73aaf7bc607c946fdd354a481262560a)
Title: Re: launching a program at specific times
Post by: kevinvinv on February 16, 2016, 07:25:58 PM
That seems weird... if I send the program into an infinite loop at the end... how will it ever respond again?  I mean,  I know it will based on examples but it seems funny to me  :)
Title: Re: launching a program at specific times
Post by: bkenobi on February 16, 2016, 08:00:59 PM
I think it's more like keeping the loop that's already running from staying running in the foreground (simple non-accurate example).  If you lower it's priority it will still run, but it will allow the system to do other things more efficiently while that task is just looping.