Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2012, 12:34 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 36
Stryker908 is on a distinguished road
Default Multi-Threading Synchronous thread crashing

Hi All I have an issue here that I'm hoping somebody can help out with... I have an app with a search button, when a user performs a search I want to resign the keyboard and display a "searching graphic" but for some reason the way I am doing it is apparently not thread safe. Is there something I'm missing here ?

Code:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
   dispatch_queue_t coreDataThread = dispatch_queue_create("com.me.coreDataThread", DISPATCH_QUEUE_SERIAL);
    dispatch_sync(coreDataThread, ^{
        
        self.activityIndicatorView = [self loadingView];
        self.activityIndicatorView.center = CGPointMake(self.view.frame.size.width /2, self.view.frame.size.height /2);
        
        dispatch_async(dispatch_get_main_queue(), ^{
        
        [self.view addSubview:self.activityIndicatorView];
        [self.view addSubview:activityIndicatorView]; 
        [self.searchBar resignFirstResponder];
        
        });
                       
    });

    
    //---------------------\\
    
    dispatch_sync(coreDataThread, ^{
        
        [self getNewDataAfterFirstResponderResigned];
        [self removeActivityIndicator];
        
    });
    
    dispatch_release(coreDataThread);
}

I am dispatching the threads synchronously because I want to create and display the spinner, as well as remove the keyboard first, then Execute the db search.....

Thanks for the time
Stryker908 is offline   Reply With Quote
Old 02-09-2012, 01:30 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Care to post the error messages &stack trace from the console?
smithdale87 is offline   Reply With Quote
Old 02-09-2012, 04:25 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

It looks like you are accessing the user interface from within a thread that is not the main UI thread. That will always cause problems.
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 390
11 members and 379 guests
chiataytuday, chits12345, fiftysixty, gmarro, KennyChong, kilobytedump, Leslie80, Matrix23, Meoz, ryantcb, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0