Page 1 of 1

Non Halting Timer

Posted: Thu Jan 31, 2008 1:28 am
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

Posted: Thu Jan 31, 2008 1:50 am
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)

Posted: Thu Jan 31, 2008 1:50 am
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! :)

Posted: Thu Jan 31, 2008 3:01 am
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.

Posted: Thu Jan 31, 2008 9:57 am
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 

Posted: Thu Jan 31, 2008 10:11 am
by TimeSurfer
baldric thank you so much that is exactly what i was looking for

KUDOS

Posted: Thu Jan 31, 2008 11:47 am
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.