1

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);
                }
            }
        }
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445

1 Answers1

3

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.

Community
  • 1
  • 1
bash.d
  • 13,029
  • 3
  • 29
  • 42
  • 1
    Hi thanks, I found the answer to my problem here (http://stackoverflow.com/questions/9453553/windows-phone-how-to-tell-when-deployment-current-dispatcher-begininvoke-has-co) –  Mar 22 '13 at 15:52