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. Visual Basic
  4. Need system clock advice.

Need system clock advice.

Scheduled Pinned Locked Moved Visual Basic
questioncsstutorial
9 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.
  • N Offline
    N Offline
    nlarson11
    wrote on last edited by
    #1

    Hello, I've written plenty of applications ran as scheduled tasks so I never had to worry about this before: When an application is being ran as windows service: What is the best way to test when the system clock hits a specific time (1:00am for example)? I know a timer is involved but is there a better way then just checking at an interval because you couldn't be sure that it would hit 1:00:00 exactly, you'd have to test a range of when it's greater then 1:00 and less then 1:01 kind of thing? Please let me know how you do it.... Thanks, Nathan

    'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

    M L B 3 Replies Last reply
    0
    • N nlarson11

      Hello, I've written plenty of applications ran as scheduled tasks so I never had to worry about this before: When an application is being ran as windows service: What is the best way to test when the system clock hits a specific time (1:00am for example)? I know a timer is involved but is there a better way then just checking at an interval because you couldn't be sure that it would hit 1:00:00 exactly, you'd have to test a range of when it's greater then 1:00 and less then 1:01 kind of thing? Please let me know how you do it.... Thanks, Nathan

      'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

      M Offline
      M Offline
      Manfred Rudolf Bihy
      wrote on last edited by
      #2

      This maybe absolute overkill for your application, but I still thought I'd point you to this: Quartz.NET[^]. It can be embedded into an application and has "tons" of useful features. Regards,

      N 1 Reply Last reply
      0
      • N nlarson11

        Hello, I've written plenty of applications ran as scheduled tasks so I never had to worry about this before: When an application is being ran as windows service: What is the best way to test when the system clock hits a specific time (1:00am for example)? I know a timer is involved but is there a better way then just checking at an interval because you couldn't be sure that it would hit 1:00:00 exactly, you'd have to test a range of when it's greater then 1:00 and less then 1:01 kind of thing? Please let me know how you do it.... Thanks, Nathan

        'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        yep, you should treat timing values the same as floating-point values, i.e. avoid equality tests. If your action has to happen at a specific time T, and must be executed for sure, then IMO you should test for T <= DateTime.Now. If the action doesn't make sense any more when a span S has elapsed, then test for *T <= DateTime.Now) And (DateTime.Now < T.Add(S)) :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        N 1 Reply Last reply
        0
        • M Manfred Rudolf Bihy

          This maybe absolute overkill for your application, but I still thought I'd point you to this: Quartz.NET[^]. It can be embedded into an application and has "tons" of useful features. Regards,

          N Offline
          N Offline
          nlarson11
          wrote on last edited by
          #4

          Thanks for the reply. Ya that's a whole lot of functionality for what I have in mind. Thanks though.

          'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

          1 Reply Last reply
          0
          • L Luc Pattyn

            yep, you should treat timing values the same as floating-point values, i.e. avoid equality tests. If your action has to happen at a specific time T, and must be executed for sure, then IMO you should test for T <= DateTime.Now. If the action doesn't make sense any more when a span S has elapsed, then test for *T <= DateTime.Now) And (DateTime.Now < T.Add(S)) :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            N Offline
            N Offline
            nlarson11
            wrote on last edited by
            #5

            Thanks for the reply. Ya I would of done it something like that. Would you choose a timer or a thread.sleep loop?

            'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

            L 1 Reply Last reply
            0
            • N nlarson11

              Thanks for the reply. Ya I would of done it something like that. Would you choose a timer or a thread.sleep loop?

              'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              nlarson11 wrote:

              Would you choose a timer or a thread.sleep loop?

              Both are doable, and my choice depends on circumstances. Threads are more expensive than timers, yet they have automatic state: your thread waits where ever you make it wait, and it knows where it is, even if inside nested methods, loops, etc. Warning: with a single thread or timer, you can't have two actions running at the same time, which could be good or bad, depends on requirements. With a thread or timer per action (which could be expensive, depending on their number) actions could overlap and interfere with each other. :)

              Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              N 1 Reply Last reply
              0
              • L Luc Pattyn

                nlarson11 wrote:

                Would you choose a timer or a thread.sleep loop?

                Both are doable, and my choice depends on circumstances. Threads are more expensive than timers, yet they have automatic state: your thread waits where ever you make it wait, and it knows where it is, even if inside nested methods, loops, etc. Warning: with a single thread or timer, you can't have two actions running at the same time, which could be good or bad, depends on requirements. With a thread or timer per action (which could be expensive, depending on their number) actions could overlap and interfere with each other. :)

                Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #7

                Thanks for the input.

                'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

                L 1 Reply Last reply
                0
                • N nlarson11

                  Thanks for the input.

                  'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  You're welcome. :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  1 Reply Last reply
                  0
                  • N nlarson11

                    Hello, I've written plenty of applications ran as scheduled tasks so I never had to worry about this before: When an application is being ran as windows service: What is the best way to test when the system clock hits a specific time (1:00am for example)? I know a timer is involved but is there a better way then just checking at an interval because you couldn't be sure that it would hit 1:00:00 exactly, you'd have to test a range of when it's greater then 1:00 and less then 1:01 kind of thing? Please let me know how you do it.... Thanks, Nathan

                    'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

                    B Offline
                    B Offline
                    Bernhard Hiller
                    wrote on last edited by
                    #9

                    Get present time. Calculate period till specified time. Start a timer to "elapse" after that period. After completion of the job, start the timer again with the same logic.

                    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