Serielle Schnittstelle in Threads ?

Windowsspezifisches Forum , API ,..
Beiträge, die plattformübergreifend sind, gehören ins 'Allgemein'-Forum.
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Serielle Schnittstelle in Threads ?

Beitrag von mk-soft »

Ich arbeite bei Threads grundsätzlich mit Strukturen...

Mal eine blödes Beispiel

Code: Alles auswählen

Structure udtThreadData
  id.i
  exit.i
  cmd.i
  state.i
  ; Data
  wait.i
  value.i
EndStructure

Global.udtThreadData thData1, thData2

Procedure thWork(*data.udtThreadData)
  
  With *data
    Repeat
      Delay(\wait)
      \value + 1
    Until \exit
  EndWith
  
EndProcedure

Debug "Start Threads..."
thData1\wait = 100
thData1\id = CreateThread(@thWork(), thData1)
thData2\wait = 200
thData2\id = CreateThread(@thWork(), thData2)

Delay(5001)

Debug "Exit Threads..."
thData1\exit = #True
If WaitThread(thData1\id, 1000) = 0
  KillThread(thData1\id)
EndIf

thData2\exit = #True
If WaitThread(thData2\id, 1000) = 0
  KillThread(thData2\id)
EndIf

Debug "Thread 1: v= " + thData1\value
Debug "Thread 2: v= " + thData2\value
P.S.
Um aus Threads Gadgets zu bearbeiten habe ich noch dieses Module

Link: ThreadToGUI
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Antworten