neowinston
neowinston

Reputation: 7764

How can I cancel performSelectorOnMainThread?

How can I cancel performSelectorOnMainThread?

I have this code:

myClass = [[MyClass alloc] init];

[myClass performSelectorOnMainThread:@selector(setupPlayer) withObject:nil waitUntilDone:YES];

Upvotes: 2

Views: 1363

Answers (2)

samvermette
samvermette

Reputation: 40437

If you're careful about the thread on which you originally queued the message, you can cancel it by calling + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget on that same thread. That previous answer was missing an important bit:

You cannot cancel messages queued using this method. If you want the option of canceling a message on the current thread, you must use either the performSelector:withObject:afterDelay: or performSelector:withObject:afterDelay:inModes: method.

Upvotes: 2

Evan Mulawski
Evan Mulawski

Reputation: 55344

Per the documentation:

You cannot cancel messages queued using this method.

Upvotes: 3

Related Questions