Quantcast
Viewing all articles
Browse latest Browse all 8223

CRM 2011 - Silverlight App that execute synchronous plug-in

Hi Im new at Silverlight/async programming

Situation: Silverlight app as a webresource that make CRUD operations

Problem: The entity have a plugin step registered to it as Synchronous. Then in silverlight when the code execute the EndSaveChages(results) method I get a SystemException. 

The message received is: "The current object did not originate the async result.\r\nParameter name: asyncResult"

I tried using a lock, Thread.Sleep, While and the Dispatcher but nothing help. There is a way to hold the process until I receive the asycResult? 

Code:

private void OnUpdateRecordComplete (IAsyncResult result)
        {
           
                    try
                    {
                        while (!result.IsCompleted)
                        {
                        }
                        Thread.Sleep(1000);
                        xrmsm_scores updatedRecord = result.AsyncState as xrmsm_scores;
                        context.EndSaveChanges(result);

                        // MessageBox.Show("Save Completed!");
                        MessageBox.Show(updatedRecord.xrmsm_studentsName.Trim() + "'s Grade has been updated!");
                        //MessageBox.Show("HUGE SUCCESS!");
                    }
                    catch (DataServiceRequestException se)
                    {
                        MessageBox.Show("The score information could not be saved.\nReason: " + getXMLError(se), "Error!", MessageBoxButton.OK);
                        studentName = string.Empty;
                        
                    }
                    catch (SystemException se)
                    {
                        isSaved = true;
                        //string error = se.Message.Replace('"', '\'').Replace("\r\n", @"\n");
                        //MessageBox.Show("OnUpdateRecordComplete SystemExeption Catch: " + error);
                       
                        //It always goes on catch because we are not using MVC System
                        //It saves it anyways :P
                        //MessageBox.Show("OnCreateRecordComplete");
                        //syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
                    }
                
           
        }


Viewing all articles
Browse latest Browse all 8223

Trending Articles



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