I am trying to make RIA service calls from non UI thread.
I made calls with opening new thread and with background workers, but for both cases callback is running on UI thread.
Is it possible to execute callback on callers thread, not UI?
Thanks

- 6,842
- 3
- 30
- 44

- 3,523
- 3
- 30
- 49
1 Answers
tl;dr
- Use WCF
- Marshal your results to the UI thread yourself
WCF RIA is built to do work on the UI thread
WCF RIA was designed to work mostly on the UI thread. That obviously has many pros and cons; mostly cons in your case. I'm having trouble finding definitive documentation of this design, however, most questions on the topic are answered by affirming the UI threadedness.
- Here is a post from a member of the WCF RIA QA team indicating UI-thread-only processing.
- Andy French describes the callbacks marshalling to the UI thread:
The Domain Context Load and SubmitChanges execute asynchronously. They take a thread from the thread pool, make the necessary calls to the server, and when those calls complete the work is automatically marshalled back to the UI thread to modify the entity collections and subsequently update the UI (probably via INotificationChanged).
If you use WCF to get your own data, you can do it on any thread you like. When the calls complete, you will have to write (or borrow) the code to update the UI on the UI thread to avoid cross thread exceptions.
IMO, the main advantages of WCF RIA giving simple problems simple solutions:
- Great tooling for re-using code between the server and client
- Service and client code are always compatible
- Transferring data to/from the client/server is relatively simple
- WCF RIA is strongly opinionated resulting in easy-to-learn coding patterns
The cons make hard problems hard or impossible:
- WCF RIA is strongly opinionated and not following that opinion is painful or impossible
- All operations return on the UI thread, often causing performance problems
- There is some voodoo to achieve the highest amount of client+server code re-use
-
Thanks for detailed answer. Unfortunately I cannot use WCF as I am working on project which already use RIA and I cannot change that part, the only way to me is to use RIA – Samvel Siradeghyan Aug 15 '12 at 19:11
-
I've achieved better performance with fewer calls to the server. The lag you see for one call grows linearly with each successive call. If you have lots of data, you can try paging. Good luck! – Ed Chapel Aug 15 '12 at 19:24
-
I am drawing something like schema of building, and loading data chunk by chunk, so I minimized data receiving delay, the problem is on data processing part, the time between data received (I am using fiddler to get that time) and completed event firing. – Samvel Siradeghyan Aug 15 '12 at 19:27