I think the problem comes from using GetGadgetText(0) from inside the branch thread
Let the main thread do it's business
Here is another point of view
No KillThread(Thread)
Code: Select all
Global StartTime,Text$
Procedure TestThread(Value)
StartTime = ElapsedMilliseconds()
While ElapsedMilliseconds() - StartTime < 10000
Debug 10000 - (ElapsedMilliseconds() - StartTime)
Debug Text$
Wend
EndProcedure
OpenWindow(0, 0, 0, 100, 70, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 80, 20, "Start Thread")
ButtonGadget(1, 10, 40, 80, 20, "End Thread")
Exit = #False
Repeat
Text$ = GetGadgetText(0)
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Thread = CreateThread(@TestThread(), 0)
Case 1
StartTime = ElapsedMilliseconds() - 9950
While IsThread(Thread) : Wend
; While IsThread(Thread) : WaitWindowEvent(1) : Wend
Debug "End !"
EndSelect
Case #PB_Event_CloseWindow
Exit = #True
EndSelect
Until Exit


