?
Solved

Timer not firing in minimized application!

Posted on 1998-11-11
13
Medium Priority
?
529 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:pswenson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1346594
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
 

Author Comment

by:pswenson
ID: 1346595
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
 

Author Comment

by:pswenson
ID: 1346596
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:dwwang
ID: 1346597
May we know where do you put the ShowWindow(Application.Handle, sw_Hide) and where to activate the timer in code?
0
 
LVL 1

Expert Comment

by:Roadrunner100598
ID: 1346598
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1346599
What sort of timers do you use?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346600
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
 
LVL 2

Expert Comment

by:Thaddy
ID: 1346601
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
 

Author Comment

by:pswenson
ID: 1346602
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
 
LVL 4

Expert Comment

by:dwwang
ID: 1346603
Have you added Timer.Active:=True in the DataModule's Create Method?
0
 

Author Comment

by:pswenson
ID: 1346604
Actually I set it directly on the datamodule via the object inspector...works the same as setting it explicitly.
0
 
LVL 2

Accepted Solution

by:
Thaddy earned 1200 total points
ID: 1346605
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
 

Author Comment

by:pswenson
ID: 1346606
I got it working... the threaded timer idea works fine.  I had other create/destroy probs that were causing the app to hang.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question