firing an event at specific time or interval

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aussie Rules

    #1

    firing an event at specific time or interval

    Hi,

    I want to be able to to have an event fired within my application at a
    certain time on certain days (such as 2am Monday, Wednesday and Friday) as
    well as other timers that fire an event based on a time interval (such as
    every 3 minutes).

    Out of the box there is the old timer1, which would cover the second
    scenario, but is there a way to have the first timer done?

    There maybe upto 50 different timers within the application.

    Thanks

  • Stephany Young

    #2
    Re: firing an event at specific time or interval

    The first thing you need to do is determine how little tolerance you can
    live with for your 'forward' time-based events. For example, will it be
    absolutely critical that they are fired at the exact time or will it be
    alright if they are fired at a point up to 'some small time span' after the
    nomintaed time (say, 1 minute)?

    If it is the former then you are going to have jump through some hoops.

    If it is the latter then it is relatively simple by implementing something
    like:

    Set the interval for your timer to the desired value,
    (say 60000 - 1 minute)

    Instantiate a queue object (preferably a generic one).
    Enqueue a DateTime object for each required 'trigger point'.
    Each 'trigger point' will represent it's next occurrence,
    (e.g., 2 AM on Friday 23 May 2008).

    When the Tick event for the timer fires, Peek the first
    object in the queue.
    If DateTime.Now >= 'the object' then DeQueue the object
    and 'fire' the appropriate event.

    In your 'event' EnQueue a new DateTime object for the next
    occurrence of the required 'trigger point',
    (e.g., 2 AM on Friday 30 May 2008).

    When the application is termintaed, the content of the queue could be
    persisted to a file and when the application is instantiated, the queue
    could be repopulated from the file, so the whole mechanism can survive
    restarts etc.


    "Aussie Rules" <aussie@nospam. comwrote in message
    news:OwtR91vuIH A.576@TK2MSFTNG P05.phx.gbl...
    Hi,
    >
    I want to be able to to have an event fired within my application at a
    certain time on certain days (such as 2am Monday, Wednesday and Friday) as
    well as other timers that fire an event based on a time interval (such as
    every 3 minutes).
    >
    Out of the box there is the old timer1, which would cover the second
    scenario, but is there a way to have the first timer done?
    >
    There maybe upto 50 different timers within the application.
    >
    Thanks

    Comment

    • Steve Gerrard

      #3
      Re: firing an event at specific time or interval

      Aussie Rules wrote:
      Hi,
      >
      I want to be able to to have an event fired within my application at a
      certain time on certain days (such as 2am Monday, Wednesday and
      Friday) as well as other timers that fire an event based on a time
      interval (such as every 3 minutes).
      >
      Out of the box there is the old timer1, which would cover the second
      scenario, but is there a way to have the first timer done?
      >
      There maybe upto 50 different timers within the application.
      >
      There is no need for 50 different timers. Just make a list of datetimes that you
      need something to happen, and what should happen.

      Have a timer that fires every minute or so. When it fires, check the list. If
      there is one that has elapsed, do that, and reset it to the next required time.
      A single timer can manage a whole list of possible calls.


      Comment

      • Just_a_fan@home.net

        #4
        Re: Re: firing an event at specific time or interval

        Funny how long it took Microsoft to decide that this was the way to do
        it. They had multiple timers instead of one timer that serviced a time
        sorted queue.

        We all had to be careful not to use too many timers. There were 16 and
        that was it! Try to use a 17th one and your program was history. And
        you have no idea how many were in use. What a stupid idea!!

        "The IRQ is in use." -- Really, WHAT IRQ???

        "The file cannot be found." -- If you would just tell me the filename, I
        COULD HELP!

        "An unexpected error has occurred." -- ALL errors are unexpected. HELP
        ME with some indication of what the error is! Oh, I see, you won't.
        Thanks?

        There are stronger answers to these STILL EXISTING error messages but
        they are not fit to type here.

        Mike

        On Tue, 20 May 2008 22:26:03 -0700, in
        microsoft.publi c.dotnet.langua ges.vb "Steve Gerrard"
        <mynamehere@com cast.netwrote:
        >Aussie Rules wrote:
        >Hi,
        >>
        >I want to be able to to have an event fired within my application at a
        >certain time on certain days (such as 2am Monday, Wednesday and
        >Friday) as well as other timers that fire an event based on a time
        >interval (such as every 3 minutes).
        >>
        >Out of the box there is the old timer1, which would cover the second
        >scenario, but is there a way to have the first timer done?
        >>
        >There maybe upto 50 different timers within the application.
        >>
        >
        >There is no need for 50 different timers. Just make a list of datetimes that you
        >need something to happen, and what should happen.
        >
        >Have a timer that fires every minute or so. When it fires, check the list. If
        >there is one that has elapsed, do that, and reset it to the next required time.
        >A single timer can manage a whole list of possible calls.
        >

        Comment

        Working...