home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <head>
- <style>
- <!--
- code { font-family: Courier New; font-size: 10pt; color: #0000FF }
- -->
- </style>
- </head>
-
- <h4>How Do I...Define complex schedules?</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 raises an event every week.<br>
- <br>
- <br>
- Now, the message ôHello World!ö will be displayed every 5 seconds each Wednesday between 7:00am and 6:00pm. <br>
- <br>
- In its simplest form, creating a Schedule 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. 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>
- 3. Defining the pattern on which to raise the event:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- WeeklyPattern days = new WeeklyPattern(DaysOfWeek.Wednesday,1);<br>
- days.StartTime = new TimeSpan(7,0,0);<br>
- days.EndTime = new TimeSpan(18,0,0);<br>
- days.Interval = new TimeSpan(0,0,5);<br>
- aSchedule.RecurrencePatterns.Add(days);</font><font face="Tahoma" size="1"><br>
- <br>
- 4. Enabling the component:<br>
- <br>
- </font><font face="Courier New" size="2" color="#0000FF">
- aSchedule.Enabled = true;</font><font face="Tahoma" size="1"><br>
- <br>
- 5. 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>
- Console.WriteLine("Hello World!");<br>
- }</font>
- </div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/Timers/ScheduleDemo">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">ScheduleDemo.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/Timers/ScheduleDemo">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/Timers/ScheduleDemo/ScheduleDemo.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/Timers/ScheduleDemo/ScheduleDemo.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->