我写了个多线程的程序,有二个按钮,点第一个先执行主线程程序,点第二个执行辅线程程序,主线程程序执行完后,辅线程程序还在执行,现在我想再执行主线程程序,但这个按钮怎么点都没用,请指点,谢谢!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type   Tgame=class(Tthread)
       constructor create();
       end;   thread1=class(Tgame)
       //constructor create();
      // procedure execute;override;
       end;    thread2=class(Tgame)
       // constructor create();
       // procedure execute;override;
       end;
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);  private
           procedure  mythreadfunc3();
            procedure  mythreadfunc4();
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure mythreadfunc1();
    var
    i,j:integer;
    begin
    j:=0;
    for i:=0 to 10000 do
    begin
    j:=j+1;
      sleep(500);
    end;
    end;
    procedure mythreadfunc();
    begin
     mythreadfunc1();
     end;constructor tgame.create();
    begin
    inherited create(false);
    freeonterminate:=true;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
    hthread:thandle;
    thid:dword;
    begin
    hthread:=beginthread(nil,0,@mythreadfunc,nil,0,thid);
    if hthread=0 then
    showmessage('fail');
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      mythreadfunc3();
    end;
    procedure tform1.mythreadfunc3();
    var
    i,j:integer;
    begin
    j:=0;
    for i:=0 to 10000 do
    begin
    j:=j+1;
    sleep(500);
    end;
    end;procedure tform1.mythreadfunc4();
    var
    i,j:integer;
    begin
    j:=0;
    for i:=0 to 10000 do
    begin
    j:=j+1;
    sleep(500);
    end;
    end;
    procedure TForm1.Button3Click(Sender: TObject);
    begin
       mythreadfunc4();
    end;end.
      

  2.   

    thread1=class(Tgame)    thread2=class(Tgame)
    TGame 是一个线程类阿
      

  3.   

    没看懂!!!
       thread1=class(Tgame)
       //constructor create();
      // procedure execute;override;
       end;    thread2=class(Tgame)
       // constructor create();
       // procedure execute;override;
       end;
    定义了咋不执行啊?
    那还有什么用!