我有一个 TThread 数组,线程是在挂起模式下创建的。 以下代码引发异常:
procedure TForm1.ButtonClick(Sender: TObject);
var
btn : TButton;
index: integer;
begin
if Sender is TButton then begin
btn := TButton(Sender);
index := btn.Tag;
if threads[index].Suspended then begin
threads[index].Resume;
btn.Caption := 'suspend ' + threads[index].id;
end
else begin
threads[index].Suspend; // <<<--- exception
btn.Caption := 'resume ' + threads[index].id;
end;
end;
end;
我知道暂停和恢复已被弃用,但我仍然想使用它们。 我想要做的事情应该很明显:如果一个线程被挂起,我想恢复它。 如果它恢复(运行),我想暂停(暂停)它。
感谢您提供的任何帮助,最好不要涉及事件的完全重写。
德尔福 11 版本 28.0.48361.3236
错误出现在过程 TMyThread.Execute 中;
我忘记了重复...直到终止,所以主体只执行一次,然后线程就完成了。很蠢,不过我用Delphi已经20年了