Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A long-running Parse operation is being executed on the main thread

I am getting the error:

"A long-running Parse operation is being executed on the main thread. Break on warnParseOperationOnMainThread() to debug."

and

"Break on warnParseOperationOnMainThread() to debug."

I'm unable to locate the error within my code. Can someone please tell me what I'm doing wrong?

PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query getObjectInBackgroundWithId:[[PFUser currentUser] objectId] block:^(PFObject *object, NSError *error) {

    self.firstName = object[@"firstname"];
    self.lastName = object[@"lastname"];

    self.nameLabel.text = [[NSArray arrayWithObjects:self.firstName, self.lastName, nil] componentsJoinedByString:@" "];
}];
like image 452
user3159704 Avatar asked Jan 08 '14 06:01

user3159704


3 Answers

This is a gentle warning to the developers when they make the Parse calls that would block the main thread.

This is where you can see it all happen,, add a symbolic breakpoint on warnBlockingOperationOnMainThread only if you use a Parse API released from 2015+. Otherwise, put it on the warnParseOperationOnMainThread.

It'll break on that function while you are running your code, and will show you a stack trace which should help you to find the blocking function.

See the images below to have a better understanding.

enter image description here

enter image description here

like image 198
Shamsudheen TK Avatar answered Nov 17 '22 17:11

Shamsudheen TK


For me this happened when I called:

[[PFUser currentUser] refresh];

The solution was to replace it with:

[[PFUser currentUser] refreshInBackgroundWithBlock:nil];

See also this answer on the Parse Help site.

like image 27
Kyle Clegg Avatar answered Nov 17 '22 18:11

Kyle Clegg


It Almost happens with all Parse queries or data saving. It avoid this, there is option to perform operation in background. Actually there are two alternatives, one is to perform in background and other is perform in background with block of code.

like image 2
Pandurang Yachwad Avatar answered Nov 17 '22 18:11

Pandurang Yachwad