1

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.Parameter 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);
    }   
}
James Wood
  • 17,286
  • 4
  • 46
  • 89

1 Answers1

0

You shouldn't have to do sleeping or waiting. My understanding is that the complete event handler is only called once async call returns.

Have you seen this sample? It should help to guide you in the right direction.

Sample: Create, Retrieve, Update and Delete Using the REST Endpoint with Silverlight

James Wood
  • 17,286
  • 4
  • 46
  • 89