我在程序中有一个定时器不断监测网络连通状态的模块,但是发现程序启来后,由于此项功能的实现总是要导致程序反映迟钝,估计是占用资源的原因,因此,我想用多线程来做,请问各位高手,该如何实现??谢谢了

解决方案 »

  1.   

    如果使用SDK的话,可以用_beginthread和来创建线程,用_endthread来结束线程。如果是用delphi的话就简单了,直接使用TThread这个类,把检测代码放到Execute函数中,启动线程就OK了,MFC的话没用过可以查查MSDN
      

  2.   

    直接使用TThread这个类,把检测代码放到Execute函数中
    我以前用在线程里面用了
    while true do 
    begin
     // 检测状态  end;
    好象也点慢,楼主可以试试看了
      

  3.   

    unit U_SearchThread;interfaceuses
      Windows, Classes, StdCtrls, Dialogs, ACTIVESKINLib_TLB;type
      MyThread = class(TThread)
      private
        procedure FindFile(Path: String);
        procedure DisplayPath;
        procedure DisplayDialog;
      protected
        procedure Execute; override;
      public
        Constructor Create(Path, PriPath, FileName: String; eLabel1,eLabel2: TSkinLabel);
        property Successed: Boolean read FBoolean;
      end;implementation{ MyThread }constructor MyThread.Create(Path, PriPath, FileName: String; eLabel1, eLabel2: TSkinLabel);
    begin
      inherited Create(False);
      ......
      FreeOnTerminate := True; //自动释放线程对象
    end;procedure MyThread.DisplayPath;
    begin
      ......
    end;procedure MyThread.DisplayDialog;
    begin
      ......
    end;procedure MyThread.Execute;
    Var
      TempStr: String;
      Count, I: Integer;
    begin
      FindFile(FPriPath);  //线程的主方法
      If Not FBoolean Then
      Begin
        Count := Length(FPath);
        For I := 1 To Count Do
        Begin
          TempStr := FPath[I] + ':';
          findFile(TempStr);
        End;
      End;  Synchronize(DisplayPath);  //同步控制界面
      Synchronize(DisplayDialog);
    end;procedure MyThread.FindFile(Path: String);
    begin
      ......
    end;
    end.这是以前写的一个线程,框架在此