Bug 13007 - Error on executing the ContinueWith on main thread
Summary: Error on executing the ContinueWith on main thread
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.9.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-07-02 09:00 UTC by Prashant Cholachagudda
Modified: 2013-07-04 06:34 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Prashant Cholachagudda 2013-07-02 09:00:11 UTC
The application randomly crashes on executing the code in ContinueWith method.

The program crashes because it says that I am trying to access the UI
thread in the thread that doesn't allow it
Comment 2 Prashant Cholachagudda 2013-07-03 10:22:53 UTC
Stack trace: 

System.AggregateException:  ---> System.Exception: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

  at MonoTouch.UIKit.UIApplication.EnsureUIThread () [0x00019] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:49

  at MonoTouch.UIKit.UITextField.get_Text () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UITextField.g.cs:910

  at InnerLenzApp.Glyph.get_Text () [0x00000] in /Users/jeff_hoffelner/Desktop/InnerLenz/InnerLenzAppIphone/Glyph.cs:259

  at InnerLenzApp.Glyph.Save () [0x0006f] in /Users/jeff_hoffelner/Desktop/InnerLenz/InnerLenzAppIphone/Glyph.cs:528

  at InnerLenzApp.Ring.Save () [0x00069] in /Users/jeff_hoffelner/Desktop/InnerLenz/InnerLenzAppIphone/Ring.cs:59

  at InnerLenzApp.InnerLenzAppViewController.<SaveRing>m__0 () [0x00000] in /Users/jeff_hoffelner/Desktop/InnerLenz/InnerLenzAppIphone/InnerLenzAppViewController.cs:276

  at System.Threading.Tasks.TaskActionInvoker+ActionInvoke.Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/TaskActionInvoker.cs:70

  at System.Threading.Tasks.Task.InnerInvoke () [0x00028] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:487

  at System.Threading.Tasks.Task.ThreadStart () [0x0007b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:390

  --- End of inner exception stack trace ---

  at System.Threading.Tasks.TaskExceptionSlot.Finalize () [0x0003e] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/TaskExceptionSlot.cs:55
Comment 3 Marek Safar 2013-07-04 06:34:21 UTC
The exception is correct. The program is trying to access UITextField::Text property from new task scheduled on thread pool thread.

The user code

				System.Threading.Tasks.Task.Factory.StartNew (() => 
				{
					mobjRing.Save (); // Save contains call to UITextField::Text
				}).ContinueWith (t => 
				{ 
					this.SaveFinish();
				}, context);

The continuation has nothing to do with it as it runs after the task failed to execute.