я использую 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>();
}
}
}
При попытке отладки приложения, он упал сразу после показа SplashScreen со следующей ошибкой:
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
Я ищу способ никогда не приостанавливать поток, так что в основном я ожидал, что метод async 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
Одно важное замечание является то, что работает, если я создавать и развертывать даже в режиме отладки, то ошибка произошла только когда я вхожу в режиме отладки (F5 из Визуальных studio 2015)
Будьте очень осторожны с «async void» здесь. Это не похоже на обработчик событий и, таким образом, метод огня и забывания. Вы должны как минимум вернуть 'Task'. Другой вопрос: что такое содержимое '_userService.Login()'? Наконец, убедитесь, что вы попробуете последние бит MvvmCross и Xamarin (есть бета-версия, которая может адресовать это с помощью нового Mono). –
. Метод Login - это просто метод получения значения токена из базы настроек (с помощью установки плагина из MvvmCross). – Jerome2606