home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <%
- runsample = Server.MapPath("/quickstart/howto/samples/Services/Timers/Scheduler")
- viewsource = "/quickstart/howto/samples/Services/Timers/Scheduler/Scheduler.src"
- icon = "/quickstart/images/genicon.gif"
- caption = "Scheduler.exe"
- %>
-
- <h4>How Do I...Execute custom code at specified times?</h4>
-
- <div class="indent" style="width:660">
- <font face="Tahoma" size="1">
- You can create a Schedule component instance for your processing that raises an event on a daily, weekly, monthly, or other calendar-based schedule.
- You can use this component to automate your business processing.
- For example, you might create a Schedule component to automatically raise events on the last Friday of every month.
- Other classes or components in your application might handle the events this component raises, for example, running logic that
- tabulates tax information for the month, computes monthly sales, and generates a monthly payroll report.<br>
- <br>
- This sample illustrates how to create a Schedule that uses the RecurrencePatternsDialog to define the pattern of when to raise events.
- Run the sample as follows:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">>
- Scheduler.exe c:\winnt\notepad.exe</font>
- <p><font face="Tahoma" size="1">
- Now, specify the schedule for opening Notepad and click OK. the specified process
- (Notepad) will start according to the pattern specified in the
- RecurrencePatternsDialog.<br>
- <br>
- In its simplest form, creating a Schedule that uses the RecurrencePatternsDialog involves:<br>
- <br>
- 1. Creating a new instance of Schedule:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF"> Schedule
- aSchedule = new Schedule();</font><font face="Tahoma" size="1"><br>
- <br>
- 2. Creating a new instance of RecurrencePatternsDialog:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- RecurrencePatternsDialog dlg = new RecurrencePatternsDialog();<br>
- dlg.RecurrencePatterns = aSchedule.RecurrencePatterns;<br>
- dlg.ShowDialog();</font><font face="Tahoma" size="1"><br>
- <br>
- 3. Setting the patterns specified through the dialog into the Schedule:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- aSchedule.RecurrencePatterns.All = dlg.RecurrencePatterns.All;</font><font face="Tahoma" size="1"><br>
- <br>
- 4. Specifying the event to raise:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- aSchedule.AddOnEventOccurred(new OccurredEventHandler(OnScheduledEvent));</font><font face="Tahoma" size="1"><br>
- <br>
- 5. Enabling the component:<br>
- <br>
- </font><font face="Courier" size="2" color="#0000FF">
- aSchedule.Enabled = true;</font><font face="Tahoma" size="1"><br>
- <br>
- 6. Defining the event to raise:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- public static void OnScheduledEvent(Object source, OccurredEvent e){<br>
- Process.Start(executablePath); <br>
- }</font><br>
- </div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/Timers/Scheduler">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">Scheduler.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/Timers/Scheduler">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/Timers/Scheduler/Scheduler.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/Timers/Scheduler/Scheduler.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->