HomeGenie Forum
General Category => Troubleshooting and Support => Topic started 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!
-
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.
-
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!
-
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)
-
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 :)
-
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.