[delphi] Thread relancement
Bonjour,
J'ai une question en rapport avec les thread (et oui encore :p). Ce que je voudrais faire c'est pouvoir relancer un thread apres qu'il soit terminer.
Voici le code de mon constructeur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
constructor TThreadFlan.create(posteFlan: TPosteFlan);
begin
if assigned(posteFlan) then
begin
FPosteFlan:= posteFlan;
FreeOnTerminate:= True; // se detruit quand il a finit son execution
inherited create(true); // NE s'execute PAS dès qu'il est crée
OnTerminate:= onTerminatedProcedure;
threadTerminated:= false;
SetLength(blocInterro, 3);
end;
end; |
Jusqu'ici tout va bien mais lorsque je teste si mon thread (apres avoir été terminer) est assigner, je remarque qu'il l'est toujours.
En effet lorsque j'execute ce code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
procedure TPosteFlan.setEnabled(value: boolean);
begin
FEnabled:= value;
if FEnabled then
begin
// si le thread s'est terminé alors on recrée l'instance pour pouvoir le relancer
if thread.threadTerminated then
thread:= TThreadFlan.create(self);
thread.Resume;
end
else
if not thread.threadTerminated then
thread.Terminate;
end; |
il rentre dans ma boucle if thread.threadTerminated alors qu'en principe mon thread doit etre libéré ( et donc delphi devrais planter :s) je ne comprend pas trop??
Sinon j'aurais voulu savoir si je ne met FreeOnTerminate:= False; dans mon create et que lorsque je recrée mon thread (thread:= TThreadFlan.create(self); ) pour pouvoir le relancer, il recrée l'instance dans la meme zone mémoire ou dans une zone différente?? Je voudrai savoir cela car mon application doit "tourner en continu" et j'aimerai eviter au maximun les fuites mémoires.
Merci d'avance pour vos reponses.
Cedric