I'm trying to do something probably very simple thing: Fill an editor gadget with a threaded
Code: Select all
cmd /c dir c:\windows\system32
Code: Select all
DisableExplicit
Enumeration EventCustomValue #PB_Event_FirstCustomValue
#MyEvent_ThreadStart
#MyEvent_ThreadUpdate
#MyEvent_ThreadEnd
EndEnumeration
Structure udtThreadStatus
line.s
EndStructure
Define thread.udtThreadStatus
Procedure GetCMDFolderContent(*thread.udtThreadStatus)
comspec$ = GetEnvironmentVariable("comspec")
DOS = RunProgram(comspec$, "/c dir c:\windows\system32", "", #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
If DOS
PostEvent(#MyEvent_ThreadStart)
While ProgramRunning(DOS)
If AvailableProgramOutput(DOS)
*thread\line = ReadProgramString(DOS)
;Debug *thread\line
PostEvent(#MyEvent_ThreadUpdate)
EndIf
Wend
CloseProgram(DOS)
PostEvent(#MyEvent_ThreadEnd)
EndIf
EndProcedure
If OpenWindow(0, 320, 320, 422, 250, "DOS Output", #PB_Window_SystemMenu)
EditorGadget(1, 8, 8, 406, 233)
*thread.udtThreadStatus = AllocateMemory(SizeOf(udtThreadStatus))
cmdThreadID = CreateThread(@GetCMDFolderContent(), *thread)
Repeat
event = WaitWindowEvent()
Select event
Case #MyEvent_ThreadStart
Debug "Thread started"
Case #MyEvent_ThreadUpdate
;Debug "Thread updated"
Debug *thread\line
;AddGadgetItem(1, -1, *thread\line)
Case #MyEvent_ThreadEnd
Debug "Thread ended"
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
When I comment that out and use the debug statement in the thread function, everything looks fine.
Why does this happen, how do I avoid this?