Stop System.Timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philip Wagenaar

    #1

    Stop System.Timer

    I have a Queue that contains filenames.
    I have a System.Timer with it's interval set to 200.

    I load the Queue up with 35.000 files. I start the Timer.

    On Timer.Elapsed I take a file from the Queue (.dequeue) and do my business
    logic on it.

    I use a Windows Forms to control all this. Start button to start the timer
    and a Stop button to stop the timer.

    But when I press the stop button the application keeps on processing files
    in Queue. The time to process a file takes longer then the 200 ms that the
    timer is set to. Is this the cause of file processing keeps on going?
    Timer.Elapsed has been triggered so many times that the application processes
    those even though I have stopped the timer?

    How can I stop the processing? By checking in my business logic code if the
    timer is enables or not? Is this a 'clean' way to solve this all?
  • Cor Ligthert [MVP]

    #2
    Re: Stop System.Timer

    Philip,

    As question first is there a reason that you do not handle the
    windows.forms.t imer, that one runs on the same thread?

    Cor


    Comment

    • Philip Wagenaar

      #3
      Reason of system.timer instead of windows forms timer

      The application is now running as a windows application. Once this works 100%
      I want to change it to run as a service and only use a windows forms for
      configuring settings. That is why I choose system.timer instead of the
      windows forms timer.

      Is there a big diffrence between the two? Instead of the thread it runs in?

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Reason of system.timer instead of windows forms timer

        Philip,[color=blue]
        >
        > Is there a big diffrence between the two? Instead of the thread it runs
        > in?[/color]

        Yes the forms timer does only run in relation to a form

        :-)

        Cor


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Stop System.Timer

          "Philip Wagenaar" <philip.wagenaa r@online.nospam > schrieb:[color=blue]
          >I have a Queue that contains filenames.
          > I have a System.Timer with it's interval set to 200.
          >
          > I load the Queue up with 35.000 files. I start the Timer.
          >
          > On Timer.Elapsed I take a file from the Queue (.dequeue) and do my
          > business
          > logic on it.
          >
          > I use a Windows Forms to control all this. Start button to start the timer
          > and a Stop button to stop the timer.[/color]

          I am curious why you are using a timer at all and which of the timer classes
          available in the .NET Framework's class library you are using.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          Working...