假设有个线程在dll里创建。
线程的execute方法如下:
while 1=1 do
begin
if Terminated then
break;
sleep(5000);
end;
在这里可能会出现一个问题。
当线程执行sleep(5000)时,那么线城会在execute方法中停留5秒,而在这5秒内,我把dll释放了。5秒后线程退出execute方法,但是这时候已经找不到该方法了,所以会出问题,应该用什么办法解决啊。

解决方案 »

  1.   

    dll释放的时候WaitForSingleObject,等待线程退出
      

  2.   

    这样的话不是要5秒后才能释放dll,如果是1分钟的话,那要等很久啊。
      

  3.   

    DWORD WaitForSingleObject(
      HANDLE hHandle,
      DWORD dwMilliseconds
    );Parameters
    hHandle 
    [in] Handle to the object. For a list of the object types whose handles can be specified, see the following Res section. 
    If this handle is closed while the wait is still pending, the function's behavior is undefined.The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.dwMilliseconds 
    [in] Time-out interval, in milliseconds. The function returns if the interval elapses, even if the object's state is nonsignaled. If dwMilliseconds is zero, the function tests the object's state and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses. 
      

  4.   

    DWORD WaitForSingleObject(
      HANDLE hHandle,
      DWORD dwMilliseconds
    );是个好的方案.
      

  5.   

    DWORD dwMilliseconds
    [in] Time-out interval