Bug 5815 - Cross-Thread Check would be more tolerant within the UIDocument
Summary: Cross-Thread Check would be more tolerant within the UIDocument
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-06-22 04:34 UTC by tome
Modified: 2012-09-04 10:04 UTC (History)
2 users (show)

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:

Description tome 2012-06-22 04:34:20 UTC
The feature on MonoTouch 5.3.x's "Cross-Thread Check" is very useful.
But I met a minor trouble around the sub-class of UIDocument.
As you know, the some of the UIDocument's methods are called from background thread,
and if you would override the method as like;

public override bool Save (NSUrl url, out NSError outError)
    return base.Save (url, out outError);  // raises UIKitThreadAccessException here

however, it just invoke the method of the base, this would be an illegal call.
To avoid this,

public override bool Save (NSUrl url, out NSError outError)
  UIApplication.CheckForIllegalCrossThreadCalls = false;
  try {
    return base.Save (url, out outError);
  finally {
    UIApplication.CheckForIllegalCrossThreadCalls = true;

I have to write this kind of code every overridden methods though not so smart.
So, could you provide a solution about that, like an Attribute to mark the method
as no-check or something. Or set a flag to the specific background thread somehow.

[DisableIllegalCrossThreadCalls] // something like this
public override bool Save ...

Thanks, I dig Mono and MonoTouch also MonoDevelop
Comment 1 tome 2012-06-23 18:43:47 UTC
As far as I know this kind of system built-in async-calls in UIKit are UIDocument only (e.g. AutoSave)
So, this title of report has changed as 'within UIDocument', and it could be treated about UIDocument only in this time.
But, I suppose that is needed which the way to avoid the check by context.
Comment 2 Sebastien Pouliot 2012-09-04 10:04:51 UTC
There's a [ThreadSafe] attribute for this - but it's used when creating bindings (i.e. at build time) and  not for user code (which would be very costly, reflection, to check at runtime).

Fixed in:
master: 3db56f90647fabb6845374a6bf196f60c8ccb901
monotouch-5.4-series: 48c016c64c607dc11931b61b56ebbdec96a26d7b