Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
I am getting a `MonoTouch.UIKit.UIKitThreadAccessException` when doing `new UILocalNotification()` from a background thread.
I don't think that's valid because Apple's docs state:
Applications that run in the allowed period in the background may also present a local notification, scheduled or immediate, to inform the user of an incoming message, chat, or update. An application can have only a limited number of scheduled notifications; the system keeps the soonest-firing 64 notifications (with automatically rescheduled notifications counting as a single notification) and discards the rest
When Apple's doc mentions "in the background," it doesn't refer to background threads, but instead the entire app running as a background app.
Additionally the documentation doesn't mention anything about thread-safety, and Apple's general recommendation about UIKit is: "For the most part, UIKit classes should be used only from an application’s main thread. "
And there also seem to be anecdotal evidence that it may crash too: http://stackoverflow.com/a/8061520/183422
So I believe the exception is in fact correct (please feel free reopen this bug report if you encounter any documentation to the contrary though)
If you really want to try and see how it goes, you can disable the thread-check:
UIApplication.CheckForIllegalCrossThreadCall = false;
var notification = new UILocalNotification ();
UIApplication.CheckForIllegalCrossThreadCall = true;
 https://developer.apple.com/library/ios/documentation/uikit/reference/UIKit_Framework/Introduction/Introduction.html at the very bottom.
I was referring to a thread that's running when the app is in the background.
Please correct me if I am wrong but an app running in the background doesn't have a main/UI thread (at least it's paused). You can only create a new thread and do your work from there.
When setting UIApplication.CheckForIllegalCrossThreadCall = false; the code works fine and local notifications are displayed as they should when my app runs in the background.
There is nothing special thread-wise when your app is executing in the background - it's just that there's another app controlling the screen.
You still have your main/UI thread, but it's just not updating any UI. You can do work there if you wish.
Can you explain how this is done?
Your own sample uses a separate thread:
When I try to run it via UIApplication.SharedApplication.BeginInvokeOnMainThread() my code won't get called.
Sorry, that was a debugger issue.
Running with UIApplication.SharedApplication.BeginInvokeOnMainThread() works without having to do UIApplication.CheckForIllegalCrossThreadCall = false;