Bug 24353 - UIApplication#BeginBackgroundTask incorrectly checks that you're running on the ui thread
Summary: UIApplication#BeginBackgroundTask incorrectly checks that you're running on t...
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: XI 8.2.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-11-07 16:00 UTC by James Moore
Modified: 2014-12-01 09:08 UTC (History)
3 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 James Moore 2014-11-07 16:00:17 UTC
I'm getting this exception:

MonoTouch.UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. at MonoTouch.UIKit.UIApplication.EnsureUIThread () [0x00023] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:70 at MonoTouch.UIKit.UIApplication.BeginBackgroundTask (System.String taskName, MonoTouch.Foundation.NSAction expirationHandler) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/UIApplication.g.cs:238 ...

Apple says that BeginBackgroundTask (well, beginBackgroundTaskWithExpirationHandler:) can be called on a non-main thread:


This method can be safely called on a non-main thread.

Using: Xamarin.iOS Version: (Business Edition)
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-11-10 06:55:43 UTC

monotouch/master: 29d174b202a7134c626076f38f733e1ff75a7ad8
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-12-01 03:58:32 UTC
@Ram, there are two BeginBackgroundTask overloads; only one had this issue.

Try this instead:

	ThreadPool.QueueUserWorkItem (_ => {
		UIApplication.SharedApplication.BeginBackgroundTask("tt", () => {});
Comment 4 Ram Chandra 2014-12-01 09:08:04 UTC
@Rolf: Thanks for the test case.

With the help of comment 3, I am able to reproduce this issue with X.iOS:

Screencast: http://www.screencast.com/t/SRQpk2heI

To verify this issue, I have checked this issue with following builds:

Mac OS X 10.10.0
Xamarin Studio: 5.7 (build 596)
Mono 3.12.0 ((detached/b75fa2b)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.1 (6604)
=== Build Information ===
Release ID: 507000596
Git revision: d996e9ba6874a0d64241e43e5e6b06322ce29c84
Build date: 2014-11-25 17:17:54-05
Xamarin addins: 8ca19707b41536a391f53364ee4ff9272711feb0

I observed that now I am not getting any error/exception when I call the "BeginBackgroundTask()" from non main thread.

Screencast: http://www.screencast.com/t/E2wo3nmy8a

This issue has been fixed. Hence I am closing this issue.