暂停线程花了超过允许的时间

时间:2017-01-25 13:59:52

标签: c# android xamarin xamarin.android mvvmcross

我使用MvvmCross并拥有一个简单的AppStart类:

public class AppStart: MvxNavigatingObject, IMvxAppStart
{
    /// <summary>
    /// The login service.
    /// </summary>
    private readonly IUserDataService _userService;

    public AppStart(IUserDataService userService)
    {
        _userService = userService;
    }

    public async void Start(object hint = null)
    {
        // If your application uses a secure API this first call attempts to log the user into the application
        // using any credentials stored from a previous session.  If there are
        // none stored we should present the login screen, else go straight into the app
        if (await _userService.Login())
        {
            ShowViewModel<MainViewModel>();
        }
        else
        {
            ShowViewModel<LoginViewModel>();
        }
    }
}

当我尝试调试应用程序时,它在显示启动画面后崩溃,出现以下错误:

suspend_thread suspend took 201 ms, which is more than the allowed 200 ms

如果我注释掉userService.Login()行,那就没关系

我升级到Xamarin 4.2.2.11后出现此错误,但我不知道它是否与此更新相关联。 我使用Xamarin.Android 7.0.2.42

我正在寻找一种永远不会挂起线程的方法所以基本上我没想到异步Start方法应该在MvvmCross中工作但似乎不是这样,或者我可能没有做好事

这是logcat日志:

    Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.Fragging[0x7f73a477de00] -> mscorlib[0x7f73a477c700]: 26
Tablet_API_21   Error   6091        suspend_thread suspend took 201 ms, which is more than the allowed 200 ms
Tablet_API_21   Debug   6091    gralloc_ranchu  Emulator without host-side GPU emulation detected.
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Platform[0x7f73abc78580] -> System.Reflection.Extensions[0x7f7394645680]: 3
Tablet_API_21   Warning 2180    IInputConnectionWrapper showStatusIcon on inactive InputConnection
Tablet_API_21   Debug   6091    OpenGLRenderer  Enabling debug mode 0
Tablet_API_21   Info    6091    OpenGLRenderer  Initialized EGL, version 1.4
Tablet_API_21   Debug   6091    OpenGLRenderer  Render dirty regions requested: true
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref VoxStarterXamarin.Droid[0x7f73a477d100] -> Xamarin.Android.Support.v4[0x7f7394618a00]: 4
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref VoxStarterXamarin.Droid[0x7f73a477d100] -> Square.AndroidTimesSquare[0x7f7394618680]: 2
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.AppCompat[0x7f73a477d380] -> Mono.Android[0x7f7394646a80]: 16
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.AppCompat[0x7f73a477d380] -> mscorlib[0x7f73a477c700]: 28
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Shared[0x7f73a477db00] -> Mono.Android[0x7f7394646a80]: 15
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Shared[0x7f73a477db00] -> mscorlib[0x7f73a477c700]: 27
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.Fragging[0x7f73a477de00] -> Mono.Android[0x7f7394646a80]: 14
Tablet_API_21   Info    1490    ActivityManager Displayed VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen: +9s623ms
Tablet_API_21   Error   1490    InputDispatcher channel '302f064b VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen (server)' ~ Channel is unrecoverably broken and will be disposed!
Tablet_API_21   Warning 1490    InputDispatcher channel '302f064b VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
Tablet_API_21   Warning 1490    ActivityManager Force removing ActivityRecord{1b02a099 u0 VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen t19}: app died, no saved state
Tablet_API_21   Info    1490    ActivityManager Process VoxStarterXamarin.Droid.VoxStarterXamarin.Droid (pid 6091) has died
Tablet_API_21   Info    1141    Zygote  Process 6091 exited due to signal (6)
Tablet_API_21   Error   1490    InputDispatcher channel '302f064b VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen (server)' ~ Channel is unrecoverably broken and will be disposed!
Tablet_API_21   Warning 1490    InputDispatcher channel '302f064b VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
Tablet_API_21   Info    1490    ActivityManager Displayed VoxStarterXamarin.Droid.VoxStarterXamarin.Droid/md5d102fb223d7168b41e10cb7cf854dfb3.SplashScreen: +9s623ms
Tablet_API_21   Error   6091        suspend_thread suspend took 201 ms, which is more than the allowed 200 ms
Tablet_API_21   Debug   6091    gralloc_ranchu  Emulator without host-side GPU emulation detected.
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Platform[0x7f73abc78580] -> System.Reflection.Extensions[0x7f7394645680]: 3
Tablet_API_21   Warning 2180    IInputConnectionWrapper showStatusIcon on inactive InputConnection
Tablet_API_21   Debug   6091    OpenGLRenderer  Enabling debug mode 0
Tablet_API_21   Info    6091    OpenGLRenderer  Initialized EGL, version 1.4
Tablet_API_21   Debug   6091    OpenGLRenderer  Render dirty regions requested: true
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref VoxStarterXamarin.Droid[0x7f73a477d100] -> Xamarin.Android.Support.v4[0x7f7394618a00]: 4
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref VoxStarterXamarin.Droid[0x7f73a477d100] -> Square.AndroidTimesSquare[0x7f7394618680]: 2
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.AppCompat[0x7f73a477d380] -> Mono.Android[0x7f7394646a80]: 16
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.AppCompat[0x7f73a477d380] -> mscorlib[0x7f73a477c700]: 28
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Shared[0x7f73a477db00] -> Mono.Android[0x7f7394646a80]: 15
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Shared[0x7f73a477db00] -> mscorlib[0x7f73a477c700]: 27
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.Fragging[0x7f73a477de00] -> Mono.Android[0x7f7394646a80]: 14
Tablet_API_21   Debug   6091    Mono    Assembly Ref addref MvvmCross.Droid.Support.V7.Fragging[0x7f73a477de00] -> mscorlib[0x7f73a477c700]: 26

一个重要的注意事项是,即使在调试模式下构建和部署也是有效的,只有当我进入调试模式时才会出现错误(来自Visual Studio 2015的F5)

1 个答案:

答案 0 :(得分:1)

每个操作系统都有一个时间限制,说明您的应用程序可以用多长时间进入第一个屏幕。 iOS对此特别严格。 MvvmCross也在启动过程中强制执行此操作。

基本上,您的await _userService.Login()需要太长时间。

您应该考虑将其移至其他地方。我的建议是为Splash Screen创建一个不同的页面,立即显示,然后在打开Splsh页面后开始登录过程。完成登录检查后,将新页面推送到Splash上​​,然后从历史记录中删除Splash页面。