I have a program with a big event loop for my main window, so I decided to create a second loop to handle specific code of a second window. I know it's not perfect...
So here is the schema of what I'm trying to do and where is my problem :
MAIN EVENT LOOP (first GUI)
|--> start 2nd Event Loop within a THREAD (second GUI)
|--> this thread start a new worker thread
|--> the worker thread PostEvent() to the second GUI (FAILED !)
The Event is received by the main event loop.
Is there a way to receive the event in the second gui ?
Thanks for your time.
Sample :
Code: Select all
Enumeration #PB_Event_FirstCustomValue
#customevent
EndEnumeration
; WORKER THREAD
Procedure WorkerThread(*value)
Debug "processing..."
Delay(2000)
PostEvent(#customevent, 1, 1)
EndProcedure
; SECOND EVENT LOOP (Threaded)
Procedure NewWINThreaded(*value)
DisableDebugger
OpenWindow(1, 100, 100, 300, 100, "Win threaded", #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_MaximizeGadget)
ButtonGadget(1, 10, 10, 100, 30, "Create Thread")
EnableDebugger
Repeat
DisableDebugger
event = WaitWindowEvent()
EnableDebugger
If event = #PB_Event_Gadget
If EventGadget() = 1
Debug "WorkerThread"
CreateThread(@WorkerThread(), 0)
EndIf
EndIf
If event = #customevent
Debug "#customevent received in Threaded Loop"
EndIf
Until event = #PB_Event_CloseWindow
EndProcedure
; MAIN EVENT LOOP
OpenWindow(0, 100, 100, 300, 100, "Main", #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_MaximizeGadget)
ButtonGadget(0, 10, 10, 100, 30, "Push me")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
If EventGadget() = 0
Debug "NewWINThreaded"
CreateThread(@NewWINThreaded(), 1)
EndIf
EndIf
If event = #customevent
Debug "#customevent received in Main Loop"
EndIf
Until event = #PB_Event_CloseWindow