小编Moh*_*eza的帖子

为什么这段代码会阻塞我的主线程?

我需要Thread独立工作Form.例如,我的循环无限Thread:

procedure TCustomThread.doProc;
begin
  repeat
.
.
.
  until (1 = 2);
end;

procedure TCustomThread.Execute;
begin
  inherited;

  Synchronize(doProc);
end;
.
.
.
procedure TForm1.Button1Click(Sender: TObject);
var
  thrd : TCustomThread;
begin
  thrd := TCustomThread.Create(True);
  thrd.Resume;
  Application.ProcessMessages;
end;
Run Code Online (Sandbox Code Playgroud)

现在,当我点击时Button1,我的Thread跑步但主要Form是锁定.我怎样才能避免暂停Form

delphi multithreading

2
推荐指数
1
解决办法
560
查看次数

为什么我的线程在表单创建后运行?

我有一个项目,主要Form是在我之后创建的Thread.但是这段代码无法正常工作:

type
  TMyThread = class(TThread)
  public
    procedure Execute; override;
    procedure doProc;
  end; { type }
.
.
.
procedure TForm1.FormCreate(Sender: TObject);
var
  thrd : TMyThread;
begin
  thrd := TMyThread.Create(True);
  thrd.Resume;

  // Following code will cause the `Form` to show the time delay is about 5 seconds...
end;
.
.
.

procedure TMyThread.Execute;
begin
  inherited;

  doProc;
end;

procedure TMyThread.doProc;
var
  AForm : TForm;
begin
  AForm := TForm.Create(nil);
  AForm.Caption := 'Thread Form';
  AForm.Position := poScreenCenter;
  AForm.FormStyle := fsStayOnTop; …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading delay

-7
推荐指数
1
解决办法
255
查看次数

标签 统计

delphi ×2

multithreading ×2

delay ×1