سؤال

I am trying to access the UI thread in C# for windows phone 8. So far I got this. However, once it runs SmartDispatcher, it jumps to finally with receipt == null.

I got the SmartDispatcher class from this website(http://www.jeff.wilcox.name/2010/04/propertychangedbase-crossthread/). I was wondering if other people had this problem and how to solve it.

private async void purchaseProduct()
        {       
            try{
                li = await Store.CurrentApp.LoadListingInformationAsync();

                SmartDispatcher.BeginInvoke(async delegate()
                {
                    receipt = await Store.CurrentApp.RequestProductPurchaseAsync(package_id, true);
                });

            }    
            catch 
            { 
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); 
            }
            finally
            {
                if(receipt != null)
                {
                    parseXML(package_id);
                    prepData();
                    httpPostData();
                    Store.CurrentApp.ReportProductFulfillment(package_id);
                }
            }
        }
هل كانت مفيدة؟

المحلول

Of course it will jump there immediately, as you are commencing an asynchronous operation, which does not block, but returns immediately.
Look, if the object contains a method Invoke instead of BeginInvoke. Invoke will block until the operation is complete.

See this thread as a reference.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top