-(Void) specified mselecw.mainthread :( SEL) aSelector withObject :( id) arg waitUntilDone :( BOOL) wait
PerformSelectorOnMainThread: withObject: waitUntilDone:
Call the method of the receiver in the main thread Based on the default mode
Invokes a method of the aggreger on the main thread using the default mode.
Parameter Parameters
ASelector
A selector that specifies the method to be called. This method should not have a clear return value and only have one id parameter at most, or there is no parameter.
A selector that identifies the method to invoke. The method shocould not have a significant return value and shocould take a single argument of type id, or no arguments.
Arg
The parameter to be passed to the call method. If there is no required parameter, pass in nil
The argument to pass to the method when it is invoked. Pass nil if the method does not take an argument.
Wait
A boolean value that specifies whether to block the current thread until the execution of the specified selector in the main thread is completed. Selecting YES will block this thread; selecting NO will immediately return this method.
A Boolean that specifies whether the current thread blocks until after the specified selector is already med on the specified er on the main thread. specify YES to block this thread; otherwise, specify NO to have this method return immediately.
If the current thread is also the main thread, select YES and the message will be distributed immediately for processing.
If the current thread is also the main thread, and you specify YES for this parameter, the message is delivered and processed immediately.
Discuss Discussion
You can use this method to send messages to the main thread. the main thread contains the main loop of the application (where NSApplication receives events ). in this case, the message is equivalent to the method of the current object you want to execute on the thread.
You can use this method to deliver messages to the main thread of your application. the main thread encompasses the application's main run loop, and is where the NSApplication object has es events. the message in this case is a method of the current object that you want to execute on the thread.
In this method, messages are added to the run loop queue of the main thread in the Common mode, that is, the mode related to the constant of the nsunloopcommonmodes. As part of its normal running and loop processing, the main thread extracts messages from the queue (assuming it is running in Common mode) and calls the required methods. When this method is called multiple times in the same thread, the corresponding selection will be queued and then retrieved and executed in the same order.
This method queues the message on the run loop of the main thread using the common run loop modes-that is, the modes associated with the nsunloopcommonmodes constant. as part of its normal run loop processing, the main thread dequeues the message (assuming it is running in one of the common run loop modes) and invokes the desired method. multiple callto this method from the same thread cause the corresponding selectors to be queued and stored med in the same order in which the callwere made.
You cannot cancel messages added to the queue by this method. to cancel a message of the current thread, you must use
Optional mselector: withObject: afterDelay: or
Optional mselector: withObject: afterDelay: inModes: method.
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
PerformSelector: withObject: afterDelay: or
Optional mselector: withObject: afterDelay: inModes: method.
Special notes
Special Considerations
This method registers the current context in runloop and relies on runloop to run regularly to ensure correct execution.(????? This cannot be translated. Please help). If you need this type of function when running a scheduling queue, you should use dispatch_after and related methods to get the desired behavior.
This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly.One common context where you might call this method and end up registering with a runloop that is not automatically run on a regular basis is when being invoked by a dispatch queue. If you need this type of functionality when running on a dispatch queue, you shocould use dispatch_after and related methods to get the behavior you want.