#ifndef NyUnit7H
#define NyUnit7H
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class MyThread : public TThread
{
private:
protected:
        void __fastcall Execute();
public:
        bool  Running;    // 是否在运行
        void (*UserProc)();
        __fastcall MyThread(bool CreateSuspended);
};
//---------------------------------------------------------------------------
#endif
#include <vcl.h>
#pragma hdrstop#include "NyUnit7.h"
#pragma package(smart_init)__fastcall MyThread::MyThread(bool CreateSuspended)
        : TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall MyThread::Execute()
{
      Running=true;    // 运行
      UserProc();      // 执行
      Running=false;  // 结束
}
//---------------------------------------------------------------------------
以上是线程内容 
 回复人:BCB(:)) (2001-6-8 12:33:00)  得0分 
bool  StopThread(void *handle)  // 强行中止一个线程,强行成功返true
{
      bool success=false;
      unsigned long ExitCode;
      if (GetExitCodeThread(handle,&ExitCode))
          if (TerminateThread(handle,ExitCode))
              success=true;
      return(success);
}
TThreadList *ThreadList=NULL;
bool  RunInThread(void (*userproc)(),unsigned int msec)
{    // 规定msec毫秒内执行用户提交的子程序,若正常结束返回true
      MyThread *thread0=new MyThread(true);
      thread0->Priority =tpHigher;
      thread0->Running=true;
      thread0->UserProc=userproc;
      thread0->Resume();    // 线程运行了
      bool  NormalEnd=true;
      unsigned int tick0=GetTickCount();
      while (thread0->Running)
          {
            if (GetTickCount()-tick0>msec)
              {      // 超时了,强行中止
                  StopThread((void *)thread0->Handle);
                  NormalEnd=false;
                  break;
              }
            Application->ProcessMessages();
          }
      if (NormalEnd)
          delete thread0;
      else
          {
              if (ThreadList==NULL)
                ThreadList=new TThreadList;
              ThreadList->Add((TThread *)thread0);
          }  // 不删了,否则时间等待太长
      return(NormalEnd);
}
杀线程部分