简体   繁体   English

应用程序的CPU使用率高达100%

[英]Application got stuck with CPU usage up to 100%

My application stuck with CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION . 我的应用程序卡在CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION In my application, I called an C function which is async. 在我的应用程序中,我调用了一个异步的C函数。 I show an waiting msg during the execution. 我在执行过程中显示了一个等待的消息。
When this function is terminated, it calls a delegate to close that waiting msg and show in same time an AlertView. 终止此函数后,它将调用委托以关闭该等待的msg,并同时显示AlertView。

I use gcd to show the alertview 我用gcd显示alertview

dispatch_async(dispatch_queue_create("com.myapp.service.waitingmessage", nil), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *anAlert = ...
            [anAlert show];
             });
        });

Here is the screenshot of the Debugger XCode when application got stuck. 这是应用程序卡住时Debugger XCode的屏幕截图。 I see also that the CPU usage of my application is up to 100%, maybe that why the application is suspended by the system. 我还看到我的应用程序的CPU使用率高达100%,这也许就是为什么该应用程序被系统挂起的原因。

在此处输入图片说明

Use dispatch_sync() in place of dispatch_async(dispatch_get_main_queue(), ^{... 使用dispatch_sync()代替dispatch_async(dispatch_get_main_queue(), ^{...

You can't update the UI from a background thread. 您无法从后台线程更新UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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