Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How do I clean up in Dispose if I can't call UIKit from another thread?

$
0
0

Most of my UIKit Dispose overrides do something with other views before they get destroyed:

protected override void Dispose (bool disposing)
{
    if (ScrollView != null) {
        ScrollView.RemoveObserver (this, new NSString ("contentOffset"));
        ScrollView.RemoveObserver (this, new NSString ("contentInset"));
        ScrollView = null;
    }

    base.Dispose (disposing);
}

I just recently realized that Dispose will run on finalizer thread if disposing is true.
In this case ScrollView.RemoveObserver will be called from non-UI thread which is Bad.

What's the safe way to do UIKit-related cleanup in Dispose?


This question was originally posted on StackOverflow.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>