Seite 1 von 1

Structure in Thread abfragen

Verfasst: 01.12.2007 16:21
von onny
Hallo,

mein Programm ist jetzt schon so groß geworden, sodadass ich kaum noch durchblicke ^^

Aufjedenfall arbeite ich gerade an Threads. Ich hab eine Structure die ich im Thread abfragen und bearbeiten will! Aber wie :,(

Ich wüsste gerade auch nicht wonach ich suchen sollte... sry.

gruß Jonas

Verfasst: 01.12.2007 18:15
von onny
Ich glaub ich habs! Wenn ich hilfe brauch, melde ich mich einfach hier nochmal! THX!

Code: Alles auswählen

Structure workdata
  command.l
  value1.l
  value2.l
  value3.l
EndStructure


Procedure workthread(*work.workdata)

  Repeat
    Debug *work\command
    Debug *work\value1
    Debug *work\value2
    Debug *work\value3
    Delay(2000)
  Until *work\command
 
  *work\command = 2
EndProcedure


Global daten.workdata

daten\value1 = 1
daten\value2 = 2
daten\value3 = 3

Debug "Start Thread"

id = CreateThread(@workthread(),@daten)

Delay(5000)

daten\value1 = 10
daten\value2 = 20
daten\value3 = 30

Delay(5000)

Debug "Thread beenden"

daten\command = 1

While daten\command <> 2: Delay(100): Wend

Debug "Thread beendet."

Verfasst: 01.12.2007 18:36
von onny
hm, wie wandel ich es so um, dass ich auch strings übertragen kann?

//edit: soweit bin ich gekommen:

Code: Alles auswählen

Structure workdata
  command.s
  value1.s
  value2.s
  value3.s
EndStructure

Procedure workthread(HILFE!!!)

  Repeat
    
    Debug work(0)\command
    Debug work(0)\value1
    Debug work(0)\value2
    Debug work(0)\value3
    Delay(2000)
  Until work(0)\command
 
  work(0)\command = "2"
EndProcedure


Global Dim daten.workdata(100)

daten(0)\value1 = "1"
daten(0)\value2 = "2"
daten(0)\value3 = "3"

Debug "Start Thread"

id = CreateThread(@workthread(),@daten)

Delay(5000)

daten(0)\value1 = "10"
daten(0)\value2 = "20"
daten(0)\value3 = "30"

Delay(5000)

Debug "Thread beenden"

daten(0)\command = "1"

While daten(0)\command <> "2": Delay(100): Wend

Debug "Thread beendet."

Verfasst: 01.12.2007 20:19
von NicTheQuick
So gehts:

Code: Alles auswählen

Structure workdata
  command.s
  Value1.s
  value2.s
  value3.s
EndStructure

Procedure workthread(*work.workdata)

  Repeat
    Debug *work\command
    Debug *work\Value1
    Debug *work\value2
    Debug *work\value3
    Delay(2000)
  Until *work\command
 
  *work\command = "2"
EndProcedure


Global Dim daten.workdata(100)

daten(0)\Value1 = "1"
daten(0)\value2 = "2"
daten(0)\value3 = "3"

Debug "Start Thread"

id = CreateThread(@workthread(),@daten(0))

Delay(5000)

daten(0)\Value1 = "10"
daten(0)\value2 = "20"
daten(0)\value3 = "30"

Delay(5000)

Debug "Thread beenden"

daten(0)\command = "1"

While daten(0)\command <> "2": Delay(100): Wend

Debug "Thread beendet."
Oder gleich so:

Code: Alles auswählen

Structure workdata
  command.s
  Value1.s
  value2.s
  value3.s
EndStructure

Global Dim daten.workdata(100)

Procedure workthread(dummy.l)

  Repeat
    Debug daten(0)\command
    Debug daten(0)\Value1
    Debug daten(0)\value2
    Debug daten(0)\value3
    Delay(2000)
  Until daten(0)\command
 
  daten(0)\command = "2"
EndProcedure

daten(0)\Value1 = "1"
daten(0)\value2 = "2"
daten(0)\value3 = "3"

Debug "Start Thread"

id = CreateThread(@workthread(),0)

Delay(5000)

daten(0)\Value1 = "10"
daten(0)\value2 = "20"
daten(0)\value3 = "30"

Delay(5000)

Debug "Thread beenden"

daten(0)\command = "1"

While daten(0)\command <> "2": Delay(100): Wend

Debug "Thread beendet."
Allerdings musst du das 'Global Dim' auch vor den Thread schreiben.