Dan Tumaykin
Dan Tumaykin

Reputation: 1253

Threading model of Windows Store application

I'm creating Windows Store application, that retrieves data asynchronously from web service and then updates the UI with the data. I've had several problems when accessing Application.Current.Resources in code(RPC_E_WRONG_THREAD).

Where I can find some explanation on how the app in launched, which threads are spawned during the app lifetime, and what I can do and access, and what can't?

Upvotes: 0

Views: 1034

Answers (1)

Faster Solutions
Faster Solutions

Reputation: 7005

Windows Store applications follow the WPF threading model in which there is a single UI thread called the Dispatcher. All UI updates/modifications/etc must occur on the dispatcher thread. The error you are getting is that you're trying to update the UI on a background thread.

.Net 4.5 uses a new async/await mechanism for managing asynchronous calls. So:

public async List<Foo> GetMyFooData()
{
    return await _myWebService.GetFooData();
}

What is happening under the hood is that an asynchronous method is being generated by the compiler so that you don't block the UI thread.

I suspect that you're trying to access Access items that are expecting to be retrieved by the Dispatcher and this is why you're erroring.

Upvotes: 3

Related Questions