ios - How can I tell if the main thread has gone away? -
i'm performing few steps background thread, updating view on completion of each using:
[self performselectoronmainthread:@selector(updateprogress) withobject:nil waituntildone:no];
the problem if user dismisses view. background thread continues run, , crashes app when gets 1 of these actions. how can tell if thread has gone away?
do intend run method updateprogress
in main thread or background thread? simple trick check. total proof should utilize nsoperationqueue
instead of performselector
synthesize bool
in viewcontroller
bool isbackgroundthreadstop;
initialize no
somewhere relevant
self.isbackgroundthreadstop = no;
when user pressed button dismiss view:
-(void)dismissview { self.isbackgroundthreadstop = yes; [self dismissmodalviewcontrollerwhatever]; }
so in method
-(void)updateprogress { if(!self.isbackgroundthreadstop){ //run programme if background thread not stop //it won't run if isbackgroundthreadstop set yes } }
ios objective-c
No comments:
Post a Comment