Autor Beitrag
bbfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 20.05.05 13:29 
Hallo!

Ich habe folgendes Problem:

Ich habe eine bestimmte Anzahl von TThread Objects erzeugt.
In einem TTimer starte ich jetzt die TThreads mit "resume".
Wir der Timer das 2. mal durchlaufen, greift "resume" nicht mehr.

Warum?

Viele Grüße,
BBFAN
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Fr 20.05.05 13:32 
Reume greift afaik nur, wenn der Thread mit TThread.Suspend pausiert wird. Ist der Thread am Ende angekommen, wird er Terminiert. Ein Resume kann dann garnicht mehr ausgeführt werden, da der Thread ja "weg" ist.

Alstar
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 20.05.05 13:41 
sowas habe ich mir auch schon gedacht.
Aber wenn ich vorher sage

ausblenden Quelltext
1:
thread.suspended:=false					


und dann resume, geht es auch nicht.

Wie kann ich es denn schaffen ein und den selben TThread mehrmals durchlaufen zulaufen in abhängigkei eines timers.

So dass, alle 3min (je timer einstellung) der thread gestartet wird.
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Fr 20.05.05 13:47 
ausblenden Delphi-Quelltext
1:
  TThread.Suspended					


ist imho eine read-only-property, sodass es nichts bringt hier einen Wert zuzuweisen.

ausblenden Delphi-Quelltext
1:
  TThread.Resume					


und

ausblenden Delphi-Quelltext
1:
  TThread.Suspend					


sind beides Gegenstücke. Resume setzt ein Thread fort, der mit Suspend angehalten wurde. Ich denke, dass dir nichts anderes übrig bleiben wird im Timer zu überprüfen, ob das Thread-Objekt noch existiert und falls nicht es wieder neu zu erzeugen.

Alstar
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 20.05.05 13:52 
ich habe ähnliches probiert:

im timer wird das TThread object mit "free" und "TerminateThread(t_id,0)" gestoppt.
und danach mit create(true) neu erzeugt.

Funktioniert soweid auch. Doch dann läuft mein Speicher Stück für Stück voll. Obwohl ich free benutze.


Zuletzt bearbeitet von bbfan am Fr 20.05.05 13:58, insgesamt 1-mal bearbeitet
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Fr 20.05.05 13:58 
Probier das TThread-Objekt mit

ausblenden Delphi-Quelltext
1:
2:
3:
Thread := TThread.Create(True);
Thread.FreeOnTerminate := True;
Thread.Resume;


zu erzeugen (oder so ähnlich). Dann wird es automatisch nach Terminierung freigegeben.

Alstar
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 20.05.05 14:02 
ok. habe ich ausprobiert.
Funktioniert zwar, aber speicher läuft mit jeder timer-umrundung immer noch voll.
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Fr 20.05.05 14:04 
Bist du sicher, dass die Variablen wirklich bei jedem Timer-Event freigegeben sind?
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Fr 20.05.05 14:06 
ja. ganz sicher.