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

Synchronous ALAsset read

$
0
0

Guys

do you see any risk in this method to read an ALAsset synchronously ?

cheers

    public static ALAsset SynchronousGetAsset(string filename)
    {
        ManualResetEvent waiter = new ManualResetEvent(false);


        NSError error = null;
        ALAsset result = null;
        Exception exception; 
        ThreadPool.QueueUserWorkItem ((object state) => {
            assetsLibrary.AssetForUrl (new NSUrl (filename),
                (ALAsset asset) => {
                    result = asset;

                    waiter.Set ();
                },
                (NSError e) => {
                    error = e;
                    waiter.Set (); 
                });
        });


        if(!waiter.WaitOne (TimeSpan.FromSeconds (10)))
            throw  new Exception("Error Getting Asset : Timeout, Asset=" + filename);

        if (error != null)
            throw new Exception (error.Description);

        return result;
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



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