more G-Labs products

Author Topic: launching a program at specific times  (Read 1221 times)

February 15, 2016, 03:37:02 AM
Read 1221 times

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
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!

February 15, 2016, 04:32:57 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
You would check IsScheduling to trigger your code.

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.

February 16, 2016, 05:12:01 AM
Reply #2

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
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!

February 16, 2016, 04:23:00 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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

February 16, 2016, 07:25:58 PM
Reply #4

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
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  :)

February 16, 2016, 08:00:59 PM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.