Skip to content

Commit 6015f5a

Browse files
committed
Improved handling of threads
1 parent 8772f17 commit 6015f5a

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

forms/mainform.pas

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3966,6 +3966,7 @@ function TformTrayslate.TranslateThread(ATrans: TTranslate; AText: string; AMemo
39663966
UpdateTranslateButtonState;
39673967
Screen.Cursor := crAppStart;
39683968
TimerAnimate.Enabled := True;
3969+
Th.Start;
39693970
try
39703971
while Assigned(Th) and (not Th.Finished) do
39713972
begin
@@ -3992,8 +3993,10 @@ function TformTrayslate.TranslateThread(ATrans: TTranslate; AText: string; AMemo
39923993
finally
39933994
if Assigned(Th) then
39943995
begin
3995-
Th.Free; // Th is nil if the thread was replaced/force-killed
39963996
FActiveThreads.Remove(Th);
3997+
if not Th.Finished then
3998+
Th.WaitFor;
3999+
Th.Free; // Th is nil if the thread was replaced/force-killed
39974000
end;
39984001
FTranslateThread := nil; // always clear shared reference
39994002
end;

units/translate.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,6 @@ constructor TTranslateThread.Create(ATrans: TTranslate; AFreeOnTerminate: boolea
17611761
FTrans := ATrans;
17621762
FSourceText := FTrans.TextToTranslate;
17631763
FCancelled := False;
1764-
Start;
17651764
end;
17661765

17671766
destructor TTranslateThread.Destroy;

0 commit comments

Comments
 (0)