Closing down problem

Just starting out? Need help? Post your questions and find answers here.
MikeB
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK

Closing down problem

Post by MikeB »

I have written a simple program to act as a speaking clock, it simply has an repeat-forever loop with a Delay(delaytime) in it to limit CPU use and plays a series of samples at the appropriate time. To check the time the delaytime is 10000 to check once every 10 seconds, until the minutes get to 14, 29, 44 or 59 and the seconds to >45, at which point the delay changes to 500 to check every half second until the correct moment (59 sec) to announce the time. The check then reverting to every 10 seconds.

This works fine except for one annoying "feature", when I shut down it causes Windows to bring up a "This Program is not Responding" requester and I have to click to kill it before Windows will close.

Any ideas on how to avoid this and still take the minimum of CPU time. (I am assuming that it is Windows trying to close it down during a delay that causes the problem).

Thanks

MikeB
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

better use a timer event for this kind of app. you can even set it to 60 secs to check only every minute.

Code: Select all

; PureBasic Visual Designer v3.70a Beta 


;- Window Constants
;
#Window_0 = 0


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 384, 305, 163, 137,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "tik...tik...")
    If CreateGadgetList(WindowID())
      
    EndIf
  EndIf
EndProcedure


Open_Window_0()

settimer_(WindowID(#Window_0),1,10000,0)  ; event every 10 secs

Repeat
  Event = WaitWindowEvent()
  
  If Event = #WM_TIMER
    Debug "TimerEvent"
  EndIf
  
Until Event = #PB_EventCloseWindow
End
Cor
Enthusiast
Enthusiast
Posts: 124
Joined: Fri Apr 25, 2003 7:52 pm
Location: Netherlands
Contact:

Post by Cor »

@Berikco
; PureBasic Visual Designer v3.70a Beta
Yeah :)
Cor de Visser

Registered PureBasic user

Author of ChordPlanet
Made with PureBasic
http://www.chordplanet.com
MikeB
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK

Post by MikeB »

Thanks Berikco,

By adding Openwindow with the window invisible flag, since I have nothing to display and simply changing the Delay bit to WaitWindowEvent and then using the KillTimer_ and SetTimer_ to change from a long to short interval and back again before and after the quarter hourly announcement the program works exactly as before, but now shuts down without the "Program not Responding" message.

I thought of reading the time and then setting the timer interval to the required amount for the announcement without the short run of half second checks, but my way will automatically allow for the clock being adjusted by a second or two when I go on-line.

MikeB
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Closing down problem

Post by PB »

> when I shut down it causes Windows to bring up a "This Program is not
> Responding" requester

I had a similar problem with one of my apps. I fixed it with the following
code in my main loop:

Code: Select all

Select WindowEvent()
  Case 0 : Sleep_(1) ; To stop 100% CPU usage when no events.
  Case #WM_ENDSESSION : Quit() ; Otherwise we slow Windows shutdown.
EndSelect
As you can see, when my app receives the #WM_ENDSESSION message,
it knows Windows is trying to shut down, so my app quits accordingly.
(BTW, you don't need the "Sleep" line for this to work).
Post Reply