locked
Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. RRS feed

  • Question

  • User124099 posted

    Got an issue report from Insights. Can't find any clue about this. Please advise.!

    UIKit.UIKitThreadAccessExceptionUIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. at UIKit.UIApplication.EnsureUIThread () [0x00023] in /Users/builder/data/lanes/1977/2c66d2fe/source/maccore/src/UIKit/UIApplication.cs:71 at UIKit.UINavigationController.get_TopViewController () [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/maccore/src/build/ios/native/UIKit/UINavigationController.g.cs:547 at Xamarin.Forms.Platform.iOS.NavigationRenderer+d28.MoveNext () [0x00058] in :0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 at System.Runtime.CompilerServices.TaskAwaiter1[System.Boolean].GetResult () [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372 at Xamarin.Forms.NavigationPage+<PopAsyncInner>d__23.MoveNext () [0x00110] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/1977/2c66d> 2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 at System.Runtime.CompilerServices.TaskAwaiter1[Xamarin.Forms.Page].GetResult () [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372 at Xamarin.Forms.NavigationPage+d1b.MoveNext () [0x001ef] in :0

    Thursday, September 10, 2015 3:20 PM

All replies

  • User1884 posted

    Looks like you are trying to pop your page on a background thread. You need to wrap your 'Navigation.PopAsync()' in Device.BeginInvokeOnMainThread

    So

    Device.BeginInvokeOnMainThread(async () => { await Navigation.PopAsync(); });

    Thursday, September 10, 2015 7:45 PM
  • User314133 posted

    Thanks @AlanSpires . In my scenario this fixed my problem.

    ActivtityIndicatorBool=true; var delay = Task.Run(async delegate { await Task.Delay(TimeSpan.FromSeconds(1)); Device.BeginInvokeOnMainThread(async () => { //whatever your process await PageNavigation.PopMainPage(); }); return 0; });

    Thursday, July 5, 2018 6:03 AM