Stop System.Timer

G

Guest

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?
 
C

Cor Ligthert [MVP]

Philip,

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

Cor
 
G

Guest

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?
 
C

Cor Ligthert [MVP]

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

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

:)

Cor
 
H

Herfried K. Wagner [MVP]

Philip Wagenaar said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top