Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's actually <strong>something directly built into Windows</strong> that will do just that. It's called the <strong>Windows Task Scheduler</strong>! Rather than having a Windows application that sits and waits for the right time to run a piece of code, you'd be better off just using an underlying system utility and storing the piece of code to run in a separate executable: it's <strong>easier</strong> and <strong>more efficient</strong>.</p> <p>I've used the Task Scheduler before to configure my applications to start on a pretty specific schedule. The best way to do it out of a .NET application is to <strong>use <a href="http://www.codeproject.com/KB/cs/tsnewlib.aspx" rel="noreferrer" title="This is the library&#39;s CodeProject article">this handy little library</a></strong>.</p> <p>Basically, to accomplish what you've stated in your question, you need to make a Windows application that provides a GUI. This GUI should have options that regulate the creation and alteration of a Task. The Task should launch the code you have to run (you should store it in a separate executable, probably as a WinForms app that's transparent and, thus, hidden.)</p> <p>Here's some code <a href="http://www.codeproject.com/KB/cs/tsnewlib.aspx" rel="noreferrer" title="This is the library&#39;s CodeProject article">from the CodeProject article of the library itself</a> that illustrates how to create a task:</p> <pre><code>//Get a ScheduledTasks object for the local computer. ScheduledTasks st = new ScheduledTasks(); // Create a task Task t; try { t = st.CreateTask("D checker"); } catch (ArgumentException) { Console.WriteLine("Task name already exists"); return; } // Fill in the program info t.ApplicationName = "chkdsk.exe"; t.Parameters = "d: /f"; t.Comment = "Checks and fixes errors on D: drive"; // Set the account under which the task should run. t.SetAccountInformation(@"THEDOMAIN\TheUser", "HisPasswd"); // Declare that the system must have been idle for ten minutes before // the task will start t.IdleWaitMinutes = 10; // Allow the task to run for no more than 2 hours, 30 minutes. t.MaxRunTime = new TimeSpan(2, 30, 0); // Set priority to only run when system is idle. t.Priority = System.Diagnostics.ProcessPriorityClass.Idle; // Create a trigger to start the task every Sunday at 6:30 AM. t.Triggers.Add(new WeeklyTrigger(6, 30, DaysOfTheWeek.Sunday)); // Save the changes that have been made. t.Save(); // Close the task to release its COM resources. t.Close(); // Dispose the ScheduledTasks to release its COM resources. st.Dispose(); </code></pre> <p><em>NOTE: The <code>priority</code> option never worked for me, always crashing the app. I recommend you leave it out; usually, it doesn't make that big a difference.</em></p> <p>There are more code samples <a href="http://www.codeproject.com/KB/cs/tsnewlib.aspx" rel="noreferrer" title="This is the library&#39;s CodeProject article">on the article page</a>, some of which show how to change the settings of a Task, list all Scheduled Tasks, etc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload