I have a Silverlight 4 application that connects to an OData service. My model is submitting multiple queries to the service in parallel and in the query callback I am processing the results using a backgroundworker.
This works great if I am making one call, but as soon as I make more than one call in parallel - sometimes it works - but most of the time I get an exception in the dataservice context when I call EndExecute (it appears to be when it is adding entities to its internal change tracking mechanism.)
So I decided to lock the data service at the point I call EndExecute
lock (dataService)
{
results = query.EndExecute(queryCallback).ToList<Video>();
}
Which fixed the problem and it now reliably processes the data requests.
My question twofold - is this a recomended practice? Is the OData context not thread safe?