有一个子线程专门读语音,我想在子线程没有执行完之前,在不退出主程序的情况下,结束子线程,怎么样实现?

解决方案 »

  1.   

    个人见解
    在子线程的可能的地方写上 if self.Terminated= true then exit;因为子线程必须执行完execute中的内容线程才结束,所以只好让他挑出这个过程才行,;
    另外在主线程中在你想结束子线程的地方写上  子线程.Terminat ,注意不能写 子线程.free
    我的程序写上free就会出现多种问题而挂死,写上Terminat 没问题。
      

  2.   

    TerminateThread - 不过注意这样终止线程可能会带来不少问题
    For example, TerminateThread can result in the following problems:If the target thread owns a critical section, the critical section will not be released. 
    If the target thread is allocating memory from the heap, the heap lock will not be released. 
    If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent. 
    If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.