Which thread makes a callback when making an asynchronous call to RIA services?

I am using the RIA DomainContext domain in a Silverlight 4 application to load data. If I use a context from a UI thread, will the callback always be in the UI thread?

Or else, is the callback always in the same thread as the call?

The sample code below illustrating the scenario ...

    private void LoadStuff()
    {
        MyDomainContext context = new MyDomainContext ();
        context.Load(context.GetStuffQuery(), op =>
        {
            if (!op.HasError)
            {
                // Use data.

                // Which thread am I on?
            }
            else
            {
                op.MarkErrorAsHandled();

                // Do error handling

            }
        }, null
        );
    }
+5
source share
1 answer

If you are executing the Load-Method for the DomainContext in the UI-Thread, then the callback is also executed in the UI-Thread.

, LoadOperation, Load.

LoadOperation<Stuff> operation = context.Load(context.GetStuffQuery());
operation.Completed += (o, e) {
  if (!operation.HasError) {
    // Use data.

    // Which thread am I on?
  }
  else {
    op.MarkErrorAsHandled();
    // Do error handling
  }
};
+3

All Articles