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 was accidentally calling UIView.SetNeedsLayout from a non GUI thread (from a Timer event handler). Understandably, the code never worked. It took me awhile to realize that calling thread is not main. Would be nice to have a warning in application output about making a GUI call from a thread different from main.
We already have this feature, see: http://tirania.org/monomac/archive/2012/Sep-10.html
This should be, by default, enabled in your debug builds. It won't be (again by default) enabled in release builds since it can have a noticeable performance impact for some code.
If you run into a case where you think you should have got this exception, but did not, then please file (or re-open) this bug report and include a test case so we can duplicate and reproduce the issue.
Thanks for the tip! It doesn't look like --force-thread-check option (is it the right one?) is enabled in the Debug configuration of my project. I tried to add the option manually (Build Options, General, iOS Build, Additional touch arguments) but unfortunately it didn't have any effect.
My code base is rather big, so I can't really extract a test case. But in a nutshell, I was trying to call UIView.SetNeedsDisplay from a System.Timers.Timer.Elapsed event handler. Not sure if it matters, but Timer was created in iOS library. And call to SetNeedsDisplay happened in iOS Application project.
You do not have to enable it - it's ON, by default,for debug build (but you can turn it off) and OFF, by default, for release (but you can turn it on).
The real issue is your choice of Timer. By design, System.Timers.Timer.Elapsed won't report the exception that monotouch.dll (or your own code) is throwing inside the event. MSDN quote :
> The Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event.
So in reality it did *not* work because the exception was thrown and the actual `SetNeedsDisplay` was never executed, nor would any code after it (try to add your own Console.WriteLine after SetNeedsDisplay and it will never be seen).
That's different from what generally happens: i.e. it works some times, does not work some times and crash (not often enough to catch while testing, too many times once deployed).
You can easily confirm this by configuring Xamarin Studio to stop on every exceptions (or specifically on UIKitThreadAccessException).
An easy way to solve this (because other exceptions could happen in your `Elapsed` event) would be to use the native timer from iOS, NSTimer.
Oh, I see. That makes total sense. I'd really like to keep my library platform independent so I guess I'll just instruct debugger to stop on exceptions I need. Thanks!