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. Timer problem with windows service

Timer problem with windows service

Scheduled Pinned Locked Moved Visual Basic
helpcareer
4 Posts 3 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.
  • M Offline
    M Offline
    Ma tju
    wrote on last edited by
    #1

    Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.

    Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
    oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000)
    
    
    Private Sub OnTimedEvent(ByVal state As Object)
        'need to stop timer..
        EventLog1.WriteEntry("Called")
        System.threading.thread.sleep(20000)' just to delay for 20 sec
        'start timer back
    End Sub
    

    Thank you in advance.

    awek Programmer Subang Jaya,Selangor, Malaysia

    H D 2 Replies Last reply
    0
    • M Ma tju

      Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.

      Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
      oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000)
      
      
      Private Sub OnTimedEvent(ByVal state As Object)
          'need to stop timer..
          EventLog1.WriteEntry("Called")
          System.threading.thread.sleep(20000)' just to delay for 20 sec
          'start timer back
      End Sub
      

      Thank you in advance.

      awek Programmer Subang Jaya,Selangor, Malaysia

      H Offline
      H Offline
      HemJoshi
      wrote on last edited by
      #2

      Hi Can you tell how much time it is taking to process the current job?Is it taking more than 10 sec? You can declare a boolean variable with value flase.S et it's value to true after completing the current job and check the value of boolean variable if it is true then only move forwad otherwise return from the time function...

      1 Reply Last reply
      0
      • M Ma tju

        Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.

        Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
        oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000)
        
        
        Private Sub OnTimedEvent(ByVal state As Object)
            'need to stop timer..
            EventLog1.WriteEntry("Called")
            System.threading.thread.sleep(20000)' just to delay for 20 sec
            'start timer back
        End Sub
        

        Thank you in advance.

        awek Programmer Subang Jaya,Selangor, Malaysia

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

        Just a thought, but why not stop the timer in your OnTimedEvent handler?? You've got the thing setup with a callback and an interval, so all you need to do at the end of the job is start the timer. At the beginning of the job, stop it.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        M 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Just a thought, but why not stop the timer in your OnTimedEvent handler?? You've got the thing setup with a callback and an interval, so all you need to do at the end of the job is start the timer. At the beginning of the job, stop it.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          M Offline
          M Offline
          Ma tju
          wrote on last edited by
          #4

          Thanks for your tips. Will try to implement it.

          awek Programmer Subang Jaya,Selangor, Malaysia

          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