2011-11-21 71 views
1

我想停止線程的執行。我使用「iscancelled」,但出現了一些問題。取消線程後,執行不會停止。如何停止執行iphone中的線程

NSLog(@"YES-------%d,%d", [myThread isExecuting], [myThread isCancelled]);//(OutPut--1,0) 
    [myThread cancel]; 
if([[NSThread currentThread] isCancelled]) 
    { 
    [NSThread exit]; 
} 
    NSLog(@"YES-------%d,%d", [myThread isExecuting], [myThread isCancelled]);//(OutPut--1,1) 

這怎麼可能,取消它的執行不會停止線程之後????

感謝,

回答

3

我敢肯定[myThread cancel]意味着信號另一個線程在你的程序中取消。

如果要取消當前線程,只是做在你的線程[NSThread exit];