我使用 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
一个重要的注意事项是,即使我在 Debug模式下构建和部署,它也能正常工作,只有当我进入 Debug模式(Visual Studio 2015 中的 F5)时才会出现错误
最佳答案
对于您的应用程序到达其第一个屏幕所需的时间,每个操作系统都有时间限制。 iOS 对此特别严格。 MvvmCross 也在他们的启动过程中强制执行这一点。
基本上,您的 await _userService.Login()
花费的时间太长。
您应该考虑将其移至其他位置。我的建议是为 Splash Screen 创建一个不同的页面,立即显示,然后在 Splsh 页面打开后开始您的登录过程。登录检查完成后,将新页面推送到 Splash 上,并从历史记录中删除 Splash 页面。
关于c# - 挂起线程花费的时间超过了允许的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41853546/