Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with Timer

Problem with Timer

Scheduled Pinned Locked Moved C#
help
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jo Develper
    wrote on last edited by
    #1

    Hi All, I am using timer in one of the application I am developing. When I try to set the interval to "2233860000.0 millisec", I am getting the following exception "Number must be either non-negative or -1.\r\nParameter name: dueTime" Here is the code snippet I am using System.Timers.Timer timerTest = new System.Timers.Timer(); timerTest.Interval = 2200920000.0; timerTest.Enabled = true; timerTest.Start(); timerTest.Elapsed +=new System.Timers.ElapsedEventHandler(time_Elapsed); Thanks in Advance, Jo

    L D 2 Replies Last reply
    0
    • J Jo Develper

      Hi All, I am using timer in one of the application I am developing. When I try to set the interval to "2233860000.0 millisec", I am getting the following exception "Number must be either non-negative or -1.\r\nParameter name: dueTime" Here is the code snippet I am using System.Timers.Timer timerTest = new System.Timers.Timer(); timerTest.Interval = 2200920000.0; timerTest.Enabled = true; timerTest.Start(); timerTest.Elapsed +=new System.Timers.ElapsedEventHandler(time_Elapsed); Thanks in Advance, Jo

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      too big for a 32-bit integer. OTOH do you really expect this program to run 25 days uninterupted? top secret
      Download xacc-ide 0.0.3 now!
      See some screenshots

      J 1 Reply Last reply
      0
      • L leppie

        too big for a 32-bit integer. OTOH do you really expect this program to run 25 days uninterupted? top secret
        Download xacc-ide 0.0.3 now!
        See some screenshots

        J Offline
        J Offline
        Jo Develper
        wrote on last edited by
        #3

        timer.Interval is double not 32 bit integer

        R 1 Reply Last reply
        0
        • J Jo Develper

          timer.Interval is double not 32 bit integer

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          You are wrong. It is Int32.

          D 1 Reply Last reply
          0
          • R Robert Rohde

            You are wrong. It is Int32.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Actually, it is documented to be a Double. Check it out here[^] and here[^] on MSDN. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            R 1 Reply Last reply
            0
            • J Jo Develper

              Hi All, I am using timer in one of the application I am developing. When I try to set the interval to "2233860000.0 millisec", I am getting the following exception "Number must be either non-negative or -1.\r\nParameter name: dueTime" Here is the code snippet I am using System.Timers.Timer timerTest = new System.Timers.Timer(); timerTest.Interval = 2200920000.0; timerTest.Enabled = true; timerTest.Start(); timerTest.Elapsed +=new System.Timers.ElapsedEventHandler(time_Elapsed); Thanks in Advance, Jo

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              It should work, but I don't have VS.NET in front of me to play around with it. Also, the other comments about having this fire 25 days later are correct. It's just not practical to assume that your code is going to be running constantly for a month straight. What are you doing with this code? There are FAR more accurate and easily implemented methods to getting a time based event running on such a long period schedule. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              J 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Actually, it is documented to be a Double. Check it out here[^] and here[^] on MSDN. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                R Offline
                R Offline
                Robert Rohde
                wrote on last edited by
                #7

                Oh, I have to admit I didnt read carefully enough. I thought he meant System.Windows.Forms.Timer. I couldnt reproduce the problem. The code works fine in my sample project.

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  It should work, but I don't have VS.NET in front of me to play around with it. Also, the other comments about having this fire 25 days later are correct. It's just not practical to assume that your code is going to be running constantly for a month straight. What are you doing with this code? There are FAR more accurate and easily implemented methods to getting a time based event running on such a long period schedule. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  J Offline
                  J Offline
                  Jo Develper
                  wrote on last edited by
                  #8

                  I am using this in a windows service. If the users dosen't shutdown the system for a longer period. I required my timer to schedule to a desired time.

                  D 1 Reply Last reply
                  0
                  • J Jo Develper

                    I am using this in a windows service. If the users dosen't shutdown the system for a longer period. I required my timer to schedule to a desired time.

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    In that case, use the timer, set at one minute, to kick off a procedure that will compare the current system time to the scheduled time of your task. If they match up, kick off your process, else do nothing. That way, if the machine gets restarted, you won't have to reset the timer to a calculated interval WAY off in the future. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    J 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      In that case, use the timer, set at one minute, to kick off a procedure that will compare the current system time to the scheduled time of your task. If they match up, kick off your process, else do nothing. That way, if the machine gets restarted, you won't have to reset the timer to a calculated interval WAY off in the future. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      J Offline
                      J Offline
                      Jo Develper
                      wrote on last edited by
                      #10

                      This is what I thought as solution. But just curious to know about the problem. Thanks, Jo.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups