Timer not firing in minimized application!

I have an application that is minimized (actually it is being hidden with "ShowWindow(Application.Handle, swHide)" and has a TrayIcon).  Anyway, on a data-module that is created by the main form I have a timer.  Sometimes the timer never fires.  Anyone have any idea why or how to fix the problem?
pswensonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ThaddyConnect With a Mentor Commented:
Did you override the threaded timer constructor? I guess not.
In addition to using a threaded timer, you need to set the default propertyvalues. The best place to do that is in the constructor(D3) or the After construction event(D4). Simply set the values there.(Like:Active:=true,interval:=10000, OnTimer:=YourtimerRoutine) From what you describe, the default values didn't get set and/or the ontimer event pointer gets lost.
0
 
viktornetCommented:
I had the same problem... The thing is that the app should show up and then be hidden.. That fixes the problems... I actually don't know why it does it, be that's the way to fix it...

Cheers,
Viktor
0
 
pswensonAuthor Commented:
I tried showing the main screen on start-up and then hiding it.  Didn't solve the problem.  Sometimes it works, sometimes it doesn't.  Remember, my timers are on a datamodule created by the main form.

Also of note, my timers need to be stopped and restarted alot.  This means if I start a timer, I may need to stop it and reset it before it fires.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
pswensonAuthor Commented:
I think the problem is that timer messages aren't queued and are considered low priority by the OS.  If I'm working in another program at the same time, then it fails almost every time.
0
 
dwwangCommented:
May we know where do you put the ShowWindow(Application.Handle, sw_Hide) and where to activate the timer in code?
0
 
Roadrunner100598Commented:
I had a similar problem (systray, message processing not working).

I solved it by not minimizing but hiding the taskbar entry only and moving the window off screen (top=9999). After that the messages where processed correctly (WMUser), I don't know if this works for Timers as well.

Some code:

.
  GetWindowRect(GetDesktopWindow, Rect);  { Find screen extend }
  MyForm.Top:=Rect.Bottom+10; { Move window off screen }
  ShowWindow(Application.Handle, sw_Hide); { Hide the taskbar entry }
.

Roadrunner
0
 
rwilson032697Commented:
What sort of timers do you use?
0
 
viktornetCommented:
Hey why not try something like...

When you need to turn on the timer just try TimerName.Update; os something like that and see if it works...

Cheers,
Viktor
0
 
ThaddyCommented:
I just tried using a Threaded timer. This fires ok everytime, since it runs as a separate thread from the minimized app.
On Torry's delphi pages is a good implementation of it.

0
 
pswensonAuthor Commented:
I tried the threaded timer idea.  It works better than a TTimer, but there are still problems.  The timer sits on a datamodule.  The main window creates the datamodule when it needs it.  Anyway, the app runs fine until the datamodule is destroyed and then recreated.  For whatever reason, when the datamodule is recreated, the timer never fires.  Same old problem..  Since the threaded timer calls synchronize, I think it is susceptible to windows messages not being processed.
0
 
dwwangCommented:
Have you added Timer.Active:=True in the DataModule's Create Method?
0
 
pswensonAuthor Commented:
Actually I set it directly on the datamodule via the object inspector...works the same as setting it explicitly.
0
 
pswensonAuthor Commented:
I got it working... the threaded timer idea works fine.  I had other create/destroy probs that were causing the app to hang.
0
All Courses

From novice to tech pro — start learning today.