Running a program as per specified schedule using C#
<p><strong>Here's the scenario.</strong><br>
Platform: Windows<br>
Language: C#<br>
.NET framework: 3.5<br>
IDE: Visual Studio 2008<br><br>
I have a working executable program written in C#. It has time scheduling facility i.e. it has a <code>numericupdown</code> box where the user can specify the number and a <code>combobox</code> where the user can specify the time duration (seconds, minutes or hours). <strong>This schedule is not for the GUI but for some specific actions/processes.</strong><br>
<strong>This is what is happening:</strong><br>
The program runs for the first time. If the user has provided some time duration to perform scheduled run again <strong>for specific actions/processes</strong> then the <strong>actions are performed</strong> as per the specified schedule but only as long as the program is running. Once the program exits then the schedule is lost.<br>
<strong>Attempt which I have made:</strong><br>
I have created a settings file which is saving the values for all the controls on the form. When the application starts the next time then this settings file is referred to load the values into the various controls on the form (including the time scheduling controls mentioned earlier). And I have also added the program in startup using the following code:<br></p>

<pre><code>[RegistryPermissionAttribute(SecurityAction.LinkDemand,Write = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run")]
        private void startup(bool add)
        {
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (add)
            {
                key.SetValue("program_name", "\"" + Application.ExecutablePath + "\"");
            }
            else
                key.DeleteValue("program_name");

            key.Close();
        }
</code></pre>

<p><br>
<strong>Problem:</strong><br>
Even though the values are getting imported from the settings file but the program is not running as per the specified time schedule.<br>
<strong>What I intend to do:</strong><br>
When the program is executed the next time either manually by user or upon system start (i.e. via startup) then the previous set schedule should be referred to and program should run again as per the schedule without user intervention. Right now it requires user intervention for the first time and then runs as per schedule as long as the application is running.<br>
Is there any way to do that? Is this what is called as making a program memory resident?<br><br>
Thanks.</p>
