How can I intentionally crash my Xamarin Android application for not using RunOnUiThread?

155 Views Asked by At

I know this sounds like a weird question.

I have a Xamarin.Android app. I'm going through my code and cleaning up stuff that was too aggressively wrapped with calls to RunOnUiThread. My understanding is that code that runs in response to UI events, for example, is already on the UI thread and therefore doesn't need to be wrapped. I don't like the idea of RunOnUiThread calls just sprinkled everywhere like magical pixie dust.

I've removed a bunch of these calls, and preserved the ones I think are necessary. When I run the app, everything works great. But not even a single crash on the first try seemed almost too good to be true, so as a sanity check, I tried to intentionally crash the app by adding UI update code in places where I expected it to be required to be wrapped by RunOnUiThread. However, nothing I do causes that effect!

This makes me concerned that there is some magic happening somewhere that is preventing me from seeing a problem.

The last thing I tried, which I thought would surely crash the app, was to use a Java.Util.Timer to execute a Java.Util.TimerTask that sets the Alpha on an ImageView to 0.5. But still the app hums merrily along!

Now I am totally suspicious that something -- maybe some new OS feature -- is silently fixing things but that customers running in some other configuration will experience crashes. I want to see the error so that I can have confidence that when I don't see it, things are OK.

So, what can I do to intentionally get the Only the original thread that created a view hierarchy can touch its views error?

0

There are 0 best solutions below