Results 1 to 5 of 5

Thread: [RESOLVED] How do you make a Timer to Tick after 3 years? :)

  1. #1

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Resolved [RESOLVED] How do you make a Timer to Tick after 3 years? :)

    Timer.Interval is an Integer, so I can't set it to more than 2^32 milliseconds I think. How would you work this around? I'd like to set some event to happen after 3 months for example. I tried to code this but I couldn't make it work... Thank you.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  2. #2
    Member
    Join Date
    Sep 2005
    Location
    West Chester, PA
    Posts
    42

    Re: How do you make a Timer to Tick after 3 years? :)

    I assume the 3 month limit would begin when the program was originally turned on. If that is the case, you write a date 3 months from then to a database or flat file, for example. Then when the program is started up, or some other event is triggered, check the current date against the date you saved out. If it is past the 3 month limit, do your action.

  3. #3
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: How do you make a Timer to Tick after 3 years? :)

    Use multiple timers. For instance, if maximum timer could only do 24 hours, and you want to trigger something in 3 days(72 hrs), then create three timers that have 24 hour intervals. Start the first timer, then when 24 hour is up, make that first timer run a code, ie. timer2.enabled = true, then that second timer starts, and when 24 hour is up, make it start timer3 with timer3.enabled = true, then when timer3 is up, then make it run whatever function you want.

  4. #4

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: How do you make a Timer to Tick after 3 years? :)

    mndepaul: Your solution works if you assume that my computer will never be turned on for more that 1 month continuously. But you did give me an idea. I will have the timer disabled by default and check in a separate thread if I have any alarm in the next week. If I do, I enable the timer and set the interval.

    benmartin101: what if I want to set an alarm after 3 years?
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] How do you make a Timer to Tick after 3 years? :)

    The Timer Interval specifies how many milliseconds between Tick events. That doesn't mean that your Timer can't Tick an indefinite number of times. Save the date and time that you want the alarm to go off and then check whether the current time is past that time at each Tick. You would set the Interval as large as your required precision allows. if you just have to make sure the alrm goes off on the right day then set your Interval to 24 hours. If you need it in the right hour then set your Interval to 1 hour. The largest possible Interval is about 25 days if I remember correctly. Whatever Integer.MaxValue milliseconds equates to in days.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width