Threaded time (No interference from other tasks)
Posted: Sun Sep 07, 2003 7:11 am
				
				I use the below code with Danilo's excellent high res timer library and it works great. It allows me to stop and start a message with every routine but it also gets interrupted by other tasks so that is a problem
Is there any way to have a timer task run independandtly of other tasks in a program such as in a thread to not get stopped or frozen?
I embedded this in another program and one task in particular that generated crc's halted the timer completely till the crc for that file was done and that isn't good.
			Is there any way to have a timer task run independandtly of other tasks in a program such as in a thread to not get stopped or frozen?
Code: Select all
#WindowIndex                            = 0
#GadgetIndex                            = 0
#ImageIndex                             = 0
#StatusBarIndex                         = 0
#MenuBarIndex                           = 0
#Window_Form1                           = #WindowIndex : #WindowIndex = #WindowIndex + 1
#Gadget_Form1_String2                   = #GadgetIndex : #GadgetIndex = #GadgetIndex + 1
#Gadget_Form1_Button3                   = #GadgetIndex : #GadgetIndex = #GadgetIndex + 1
;==================================================================================================
Global TimerTicks.l
;==================================================================================================
Procedure.l Window_Form1()
  If OpenWindow(#Window_Form1,175,0,400,300,#PB_Window_SystemMenu|#PB_Window_Invisible,"Work Form1")
    If CreateGadgetList(WindowID())
      StringGadget(#Gadget_Form1_String2,10,270,300,20,"")
      ButtonGadget(#Gadget_Form1_Button3,325,270,60,20,"Button3")
      HideWindow(#Window_Form1,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure
;==================================================================================================
Procedure BlinkMessage()
  While WindowEvent() : Wend
  SetGadgetText(#Gadget_Form1_String2, "Working...")
  TimerTicks + 1
  If TimerTicks = 2
    TimerTicks = 0
    While WindowEvent() : Wend
    SetGadgetText(#Gadget_Form1_String2, "")
  EndIf
EndProcedure
;==================================================================================================
If Window_Form1()
  StartTimer(0, 1000, @BlinkMessage())
  
  quitForm1 = 0 
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=#Window_Form1
          quitForm1=1
        EndIf
      Case #PB_Event_Menu
        Select EventMenuID()
        EndSelect
      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case #Gadget_Form1_String2
          Case #Gadget_Form1_Button3  : EndTimer(0)
        EndSelect
    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End