Board index » delphi » TTimer.OnTImer still firing after enabled set to false

TTimer.OnTImer still firing after enabled set to false

Here's the deal:

I want to have a splash screen with a ProgressBar incremented by a TTImer
OnTImer event to run while I do some background database and application
processing.  I did this by creating a TThread which does the background
processing then disabling the TTimer and closing the splash screen in the
OnTerminate event of the Thread.

The problem is, even though I step through the code and can see the line
Timer.Enabled := False being processed (even tacking on an
Application.ProcessMessages for good measure), the OnTimer event is still
firing which causes a looping AccessViolation.

Any ideas?

Pam

 

Re:TTimer.OnTImer still firing after enabled set to false


Quote
> I want to have a splash screen with a ProgressBar incremented by a TTImer
> OnTImer event to run while I do some background database and application
> processing.  I did this by creating a TThread which does the background
> processing then disabling the TTimer and closing the splash screen in the
> OnTerminate event of the Thread.  
> The problem is, even though I step through the code and can see the line
> Timer.Enabled := False being processed (even tacking on an
> Application.ProcessMessages for good measure), the OnTimer event is still
> firing which causes a looping AccessViolation.

Where, exactly, do you have this timer.enabled statement? If you create the
timer in the main thread then it needs to be disabled in the main thread.
Doing it inside the Onterminate handler should work since that is executed
via Synchronize. Doing at the end of the threads Execute method will not
work. You can disable the timer handler by simply assigning Nil to the
timers OnTimer event, by the way.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:TTimer.OnTImer still firing after enabled set to false


It is indeed in the OnTerminate event.  Haven't tried assigning nil to
the OnTimer event (although the close of the form with the timer sets
the entire form to nil).  I'll give that a try.

Pam

Quote
"Peter Below (TeamB)" wrote:

> Where, exactly, do you have this timer.enabled statement? If you create the
> timer in the main thread then it needs to be disabled in the main thread.
> Doing it inside the Onterminate handler should work since that is executed
> via Synchronize. Doing at the end of the threads Execute method will not
> work. You can disable the timer handler by simply assigning Nil to the
> timers OnTimer event, by the way.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Other Threads