Reputation: 3221
I'm using a RIA Services DomainContext in a Silverlight 4 app to load data. If I'm using the context from the UI thread, is the callback always going to be on the UI thread?
Or put another way, is the callback always on the same thread as the call?
Some example 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
);
}
Upvotes: 5
Views: 316
Reputation: 35544
If you execute the Load-Method of the DomainContext on the UI-Thread, then is the callback also executed on the UI-Thread.
This is also true, when you use the Completed-Event of the LoadOperation returned by 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
}
};
Upvotes: 3