WaitForSingleObject(hEvent, INFINITE);
  while not Terminated do
  begin
    GetURL;//这个过程是从库里得到网址给"Furl" 变量
   html := Fhttp.Get(Furl); //执行下载网页 "Furl" 
 CrackLink(html, taskName, web_rank, Furl);//分析连接加入数据库
 end;
目前程序运行一一段时间就停了 但库里还有网址 不知道为何停止
这个 WaitForSingleObject(hEvent, INFINITE);放的位置对不对 该如何使用
如何让这个线程一值运行 直到库里没有连接为止

解决方案 »

  1.   

    WaitForSingleObject你的本意是用它来干嘛呢?
    没看出它对本过程的影响,而时间又是一直等待,不好判断,还有你的GetUrl是不是取一条就剔除一条呢?
      

  2.   

    WaitForSingleObject目的想使线程一直运行着
    GetUrl 是个临界区已经cs.enter cs.leave. 它里面通过库里ID字段 当一线程访问过 我就记下当前的ID 下次再执行 就找大于这个ID的值 再记下这次读取ID值 反反复复
      

  3.   

    是不是这么理解,WaitForSingleObject就是等待数据库中有一条记录,然后执行GetUrl以及之后的?
    如果是,应该放在While 中去,结束线程注意要先销毁hEvent
      

  4.   

    使用while not terminated do循环就可以了
    在里边加入库地址总数,然后加个判断是否大于了库地址数,这样就行了
      

  5.   

    可能是GetUrl里面临界区使用不当,导致多线程死锁?
      

  6.   

    主要就是防止enter了,没leave就exit了
    另外,enter与leave间的代码尽量减少,一是提高效率,减少不必要的互相等待;二是逻辑简单,不至于不小心出现我上面说的非正常exit。
      

  7.   


    共享列表,有个专门的类:TthreadList停、启线程:Suspend and Resume:A thread can be started and stopped any number of times before it finishes executing. To stop a thread temporarily, call its Suspend method. When it is safe for the thread to resume, call its Resume method. Suspend increases an internal counter, so you can nest calls to Suspend and Resume. The thread does not resume execution until all suspensions have been matched by a call to Resume.You can request that a thread end execution prematurely by calling the Terminate method. Terminate sets the thread's Terminated property to True. If you have implemented the Execute method properly, it checks the Terminated property periodically, and stops execution when Terminated is True.