ios - Objective-c verify the current execution thread and, in case, re execute the method in the correct thread -


I am trying to create a single method to check if I am the current thread and if it is different from the desired (( Collar) Repeat the method in the correct thread.

I am using:

  - (zero) aMethod: (id) aParam {[Self execution intraTrade]; ...}  

The current code is:

  - (minus) executeInRightThread {NSString * rightQueueLabel = [NSString stringWithCString: dispatch_queue_get_label (myQueue) encoding: NSUTF8StringEncoding]; NSString * currentQueueLabel = [NSString stringWithCString: dispatch_queue_get_label (DISPATCH_CURRENT_QUEUE_LABEL) Encoding: NSUTF8StringEncoding]; BOOL is InTheRightQueue = [currentQueueLabel is EqualToString: rightQueueLabel]; NSString * sourceString = [[NSThread call staxsimmoles] ObjectAutindex: 1]; // Example: 1 UIKit 0x00540c89 - [UIApplication _callInitializationDelegatesForURL: Payload: Suspended:] 1163 NSCharacterSet * separatorSet = [NSCharacterSet characterSetWithCharactersInString: @ "-. [],"]; NSMutableArray * array = [NSMutableArray arrayWithArray: [SourceString ComponentsApprovedBearectors Inset: Separator Set]]; [Array deleted object: @ ""]; // NSLog (@ "stack =% @", [array ObjectEndIndex: 0]); // NSLog (@ "Framework =% @", [Array ObjectOut Indices: 1]); // NSLog (@ "Memory Address =% @", [Array ObjectAntindex: 2]); // NSLog (@ "Class Caller =% @", [Array ObjectTitx: 3]); // NSLog (@ "Function Collar =% @", [Array ObjectTitx: 4]); // NSLog (@ "line caller =% @", [array objectattack index: 5]); NSString * callerMethodName = [Array ObjectTitx: 4]; If (HinriteQueu in!) {Send_assack (mine queue, ^ {[self performance selector: nsselector frostring (caller methodname);}); }}  

executeInRightThread method works well, but I do not know how to get the caller method parameter (eg aParam), I do not want < Pass the parameter for Code> executeInRightThread method, the main purpose is useful everywhere, without using blocks and without the various parameters nearby.

Use NSThread currentThread for the query of the current thread. However, your question is a little confused, because then you specify the variable isInRightQueue .

You are currently queue can not query - dispatch_get_current_queue () that went to be excluded, and return not always what you expect (and dispatch_queue_get_label (DISPATCH_CURRENT_QUEUE_LABEL) Really the same problem) We ran into a case on iOS 8 where AVCaptureVideoOutput was configured to call us back on the main line. Call back, we found that return results dispatch_get_current_queue () What we expected (we basically said was not setSampleBufferDelegate: ... line: dispatch_get_main_queue () , but instead:

  (lldb) Po dispatch_get_current_queue () of & lt; OS_dispatch_queue: com.apple.avfoundation.videodataoutput.bufferqueue [0x170118e40] = {xrefcnt = 0x1, 0x3 refcnt = , suspend_cnt = 0x0, closed = 1 target = com.apple.main thread [0x1001be800], width = 0x0, running = 0x0, barrier = 1} & gt; (lldb) p (char *) dispatch_queue_get_label (zero) (Four *) $ 4 = 0x000000017026f8c0 "com.apple.avfoundation.videodataoutput.bufferqueue" (lldb) p (four *) dispatch_queue_get_label ((d Ispatch_queue_t [captureOutput sampleBufferCallbackQueue]) (four *) $ 6 = 0x00000001001af6b0 "com.apple.main thread"  

Note that this is the main line of the main thread instead of the target row.

There is no mapping between the queue and the thread. There was a queue executing on the background thread - in front of the main thread - can execute on any background thread.

General case where to examine the execution thread if you want to implement the code which affects the UI.

  if (! [NSThread isMainThread]) {dispatch_sync (sender_gate_man_clline (), ^ {....}); }  

If you need to verify that you have been recalled back to the correct background queue, you may need to think more clearly about your application logic. However, if you really need to do this, why not sync a sendmail_ in the relevant background queue. This will delay the execution of your desired work, but since you are already in the background, it probably does not matter.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -