Code : Tout sélectionner
[17:11:16] [ERROR] OpenWindow() can only be called from the main thread.
merci
Code : Tout sélectionner
[17:11:16] [ERROR] OpenWindow() can only be called from the main thread.
Code : Tout sélectionner
Global X, TOTO = 0
Procedure procethread(*valeurfictive)
Repeat
Delay(1000)
X+1
SetGadgetText(1, Str(x) + "/10")
Until x = 10
If x = 10
TOTO = 1
Else
TOTO = 0
EndIf
Debug "valeur de toto : " + TOTO
; on sort du thread
EndProcedure
OpenWindow(0,0,0,200,50,"teste",#PB_Window_SystemMenu)
StringGadget(1,0,0,150,20,"")
MonThread = CreateThread(@procethread(),*valeurfictive)
Repeat
event=WaitWindowEvent(1)
If toto = 1
If IsThread(MonThread)
SetGadgetText(1," Thread actif")
Else
SetGadgetText(1," Il ni a plus de thread")
EndIf
EndIf
Until event=#PB_Event_CloseWindow
;Dans le cas ou l'on quitte le prog inopinément
If IsThread(MonThread)
Debug "Thread en cours... Je le tue"
KillThread(MonThread)
; Je reteste ^^ pour l'exemple
If IsThread(MonThread)
Debug "Thread en cours... Je le re-tue, ce qui n'est pas normal"
KillThread(MonThread)
Else
Debug "Il est mort, je quitte..."
EndIf
EndIf
Une solution:OpenWindow() can only be called from the main thread.
Code : Tout sélectionner
; Ouvrir une fenêtre depuis un thread
; La fenêtre 2 est générée hors thread en mode invisible
; Le thread la rend visible
; --- Fenêtre principale
OpenWindow(0, 0, 0, 500, 300, "First",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; --- Seconde fenêtre (invisible lors de la création: #PB_Window_Invisible)
OpenWindow(1, 0, 0, 250, 450, "Second",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
TextGadget(#PB_Any, 10, 10, 200, 30, "On me demande ? j'étais derrière.")
Procedure MaProcedureThread(*Valeur)
Delay(3000)
HideWindow(1, #False)
Delay(3000)
HideWindow(1, #True)
EndProcedure
CreateThread(@MaProcedureThread(), 23)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend