C# 挂起线程花费的时间超过了允许的时间

C# 挂起线程花费的时间超过了允许的时间,c#,android,xamarin,xamarin.android,mvvmcross,C#,Android,Xamarin,Xamarin.android,Mvvmcross,我使用MvvmCross并有一个简单的AppStart类: public class AppStart: MvxNavigatingObject, IMvxAppStart { /// <summary> /// The login service. /// </summary> private readonly IUserDataService _userService; public AppStart(IUserDataSer

我使用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>();
        }
    }
}
如果我注释掉userService.Login()行,就可以了

这个错误是在我升级到Xamarin 4.2.2.11之后出现的,但我不知道它是否链接到这个更新。 我使用Xamarin.Android 7.0.2.42

我正在寻找一种永远不会挂起线程的方法,所以基本上我希望异步启动方法可以在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)时才会发生错误。

每个操作系统都有一个时间限制,限制您的应用程序到达第一个屏幕所需的时间。iOS对此特别严格。MvvmCross也在其启动过程中强制执行这一点

基本上,您的
wait\u userService.Login()
花费的时间太长


你应该考虑把这个搬到另一个地方去。我的建议是为启动屏幕创建一个不同的页面,立即显示,然后在打开Splsh页面后开始登录过程。登录检查完成后,将新页面推到启动页面上,并从历史记录中删除启动页面。

在此处使用
async void
时要非常小心。它似乎不是一个事件处理程序,因此是一个fire-and-forget方法。您应该至少返回
任务
。另一个问题是,
\u userService.Login()的内容是什么?最后,请确保您尝试了MvvmCross和Xamarin的最新版本(有一个Beta版本,可能会使用新的Mono解决这个问题)。登录方法只是一种从设置库获取令牌值的方法(使用MvvmCross的设置插件)。实际上,我使用的是MvxSplashscreen,我希望MvvmCross能够处理这种事情。因此,您的建议是显示包含相同splashscreen的视图模型,在该视图模型内执行登录过程,然后加载loginView或mainView。对吧?没错!MvxSplashscreen在技术上仍然不是应用程序启动过程的一部分。基本上,
IMvxAppStart.Start
有时间限制。所以你在那里跑的每一步都必须在200毫秒内完成。正如@SuavePirate指出的,更长的进程应该从其他地方启动。在
AppStart
中,您尚未设置
Root
ViewController
,这是由您的
ShowViewModel
调用完成的。在这里花费太长时间将产生您看到的错误。MvvmCross在此不强制执行任何时间限制。不过,操作系统对此非常严格。
    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