简体   繁体   中英

How long has my iOS application been running on main thread?

I am new to concurrency and trying to understand how to make my app perform better. I am trying to figure out if there is a way for me to find out how long my app has been running/ performing operations on the Main thread .

And is that the way to go about it if I am trying to make my app perform better. Thanks in advance.

Few things to consider in concurrency in iOS .

  • All your UI/ UIApplication related task will executed in Main thread , you should never perform your UI task in any secondary thread.
  • If you have anything long running task like server connection and downloading data processing the data or any business logic calculation which is not related to UI should execute in different thread.

When your app start, system creates the main run loop and the main thread for you and by default all tasks runs on the Main thread. So as I listed above you can create a secondary thread using GCD or NSOperationQueue to execute long running tasks which are not related to UI. Because if you don't create a secondary thread for the long running tasks and you run this on Main thread only, then your UI will stuck till the task is over, which is obviously not a good user experience.

To understand GCD and NSOperationQueue check this link: https://www.raywenderlich.com/817-updated-course-ios-concurrency-with-gcd-operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM