读书人

一个Delphi7 多线程的有关问题,答案!

发布时间: 2013-09-06 10:17:17 作者: rapoo

一个Delphi7 多线程的问题,在线等答案!!!

unit Unit2;
interface
uses
Classes;
type
MyTh = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
uses Unit1;
{ MyTh }
procedure MyTh.Execute;
begin
{ Place thread code here }
unit1.Form1.mypro;
end;
end.

在 procedure Execute里执行的是一个mypro过程,一个程序里有多个过程(Myfun,Myfun1,Myfun3)需要用到多线程,请问需要怎么处理? Delphi 多线程
[解决办法]
建立三个类似MyTh的线程类。然后声明三个线程对象。分别执行就可以了。
[解决办法]
用Createthread 或者Thread 把Myfun,Myfun1,Myfun3分别写到三个过程中 ,并发执行
[解决办法]
unit Unit2;
interface
uses
Classes;
type
TMyTh1 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

TMyTh2 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

TMyTh3 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

implementation
uses Unit1;
{ TMyTh1 }
procedure TMyTh1.Execute;
begin
{ Place thread code here }
Synchronize(unit1.Form1.mypro1);
end;

{ TMyTh2 }
procedure TMyTh2.Execute;
begin
{ Place thread code here }
Synchronize(unit1.Form1.mypro2);
end;

{ TMyTh3 }


procedure TMyTh3.Execute;
begin
{ Place thread code here }
Synchronize(unit1.Form1.mypro3);
end;


end.

读书人网 >.NET

热点推荐