这是有API实现的======》》》
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
GroupBox1: TGroupBox;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
sushuThread
word;
shuixianhuaThread
word;
jieguo:boolean;
implementation
{$R *.dfm}
procedure shuixianhua_Thread;
var
i,g,s,b,m:integer;
hand:Thandle;
begin
hand:=CreateEvent(nil,FALSE,FALSE,'qq');
for i:=100 to 999do
begin
g:=i mod 10;
s:=(i div 10) mod 10;
b:=i div 100;
m:=g*g*g+s*s*s+b*b*b;
if i=m then
begin
form1.ListBox1.Items.Add('shuixianhuaThread线程求得的------水仙花数是:'+inttostr(i));
form1.ListBox1.Items.Add('');
WaitForSingleObject(hand,1000);
ResumeThread(sushuThread);
SuspendThread(shuixianhuaThread);
end;
end;
ResumeThread(sushuThread);
jieguo:=true;
end;
procedure sushu_Thread;
var
i,j:integer;
fell:boolean;
hand:Thandle;
begin
hand:=CreateEvent(nil,FALSE,FALSE,'qq');
jieguo:=false;
for i:=3 to 100do
begin
fell:=TRUE;
for j:=2 to i-1do
begin
if (i mod j) =0 then
begin
fell:=False;
break;
end;
end;
if fell then
begin
Form1.ListBox1.Items.Add('sushuThread线程求得的------素数是:'+inttostr(i));
Form1.ListBox1.Items.Add(' ');
WaitForSingleObject(hand,1000);
ResumeThread(shuixianhuaThread);
if not jieguo then
SuspendThread(sushuThread);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
code1
word;
code2
word;
begin
ListBox1.Items.Clear;
sushuThread:=createthread(nil,0,@sushu_Thread,nil,0,code1);
shuixianhuaThread:=createthread(nil,0,@shuixianhua_Thread,nil,CREATE_SUSPENDED,code2);
end;
end.
用delphi的线程类,能够实现线程的挂起后并保存当前的状态,当被唤醒时继续工作吗。也就是当在次唤醒这个线程后不会重新开始在执行! 牛哥门(小第急。。。)