Non Halting Timer

Just starting out? Need help? Post your questions and find answers here.
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Non Halting Timer

Post by TimeSurfer »

Is there a way I can make a timer that doesnt halt the application that uses it? I'm trying to make a timer dll for use in autoplay media studio 7 and after several different attempts all my efforts are leaving me frustrated as the timer seems to halt the application till its done.

any ideas would great
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Post by eriansa »

not sure what you mean by halting the app, but a multimedia timer runs in it's own thread :
hTimer = timeSetEvent_(1, 0, @myTimerCallback(), 0, #TIME_PERIODIC)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Either use a thread instead, or when you receive the #WM_TIMER message, call a thread to do the necessary work etc. You'll probably need to add some logic to ensure you don't have more than one such thread running at a time etc.

**EDIT : or do what eriansa said! :)
I may look like a mule, but I'm not a complete ass.
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post by TimeSurfer »

by halting i mean that when i call the dll it seems to prevent my application from doing anything till the timer finishs. I need the timer to run in the background.
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

Maybe this is what u seek

Code: Select all

Procedure proc() 
  Debug "proc called via Settimer thread" 
EndProcedure 

If OpenWindow(0,0,0,200,100,"Test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) 
  If CreateGadgetList(WindowID(0)) 
   StringGadget(0,10,10,50,20,"1",#PB_String_Numeric) 
   ButtonGadget(1,10,70,50,20,"Run") 
   ButtonGadget(2,70,70,50,20,"Stop") 
  EndIf 
EndIf 

Repeat 
  Ev=WaitWindowEvent(1) 
  Tmr.l=ElapsedMilliseconds() 
  
   If Ev=#PB_Event_Gadget 
    Select EventGadget() 
     Case 1 ;run btn
      period=Val(GetGadgetText(0))*1000 
       If period<1000 
        period=1000 
       EndIf 
       Settmr=SetTimer_(WindowID(0), 1, period, @proc()) ;start api timer thread 
       Debug "timer started"
     Case 2 ;stop btn
      If Settmr 
       KillTimer_(WindowID(0),Settmr); kill api timer 
       Settmr=0 
       Debug "timer stopped"
      EndIf 
    EndSelect 
   EndIf 
    
Until Ev=#PB_Event_CloseWindow 
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post by TimeSurfer »

baldric thank you so much that is exactly what i was looking for

KUDOS
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, any timer created with SetTimer_() does not actually run in the background; it runs within the process which created it and is processed only when DespatchMessage_() find a #WM_TIMER message etc. The messages themselves are posted to the processes message queue 'in the background' by Windows itself, but not the actual processing thereof which will run and halt the main process etc.
I may look like a mule, but I'm not a complete ass.
Post Reply