Currently I have a WCF method which brings back all the data from the db and binds it to a grid, but I would like to call this method regularly to get the updated data back each time, to show the user real time data, what is the best way to go about this?
Thanks in advance.
-
What have you thought to try? AJAX timer? Some other timing mechanism?sq33G– sq33G2011年11月20日 19:27:41 +00:00Commented Nov 20, 2011 at 19:27
-
1WebSockets of Server Sent events are your friends for real timeRaynos– Raynos2011年11月21日 01:03:05 +00:00Commented Nov 21, 2011 at 1:03
-
AJAX? WebSockets? The question specifies Silverlight...Nicholas W– Nicholas W2011年11月21日 13:11:46 +00:00Commented Nov 21, 2011 at 13:11
-
Define "real time" before proceeding.Wyatt Barnett– Wyatt Barnett2012年01月20日 01:57:19 +00:00Commented Jan 20, 2012 at 1:57
3 Answers 3
Check parapura's answer in this Question.
This approach is called long polling, its simple and should provide you the data you want whenever its available from the server side.
Check this Blog for more detailed sample class.
Hmmm,
I do not know what your application function is, but could you try something like this?
- What puts the data in your db constantly? Why not just give that to your grid ( might need a bit of formatting and data hiding of course / or store data at application level up to certain limit ) That way you are absolute real time.
Now, to update db why not make a db update when a grid add 10 rows or something from that application level storage or your data grid.
- This makes you have less db calls , increasing latency. Also makes you real time.
- Thoughts?
I would create a backgroundworker thread and put it into an endless loop. You could send the request to the service asynchronously if a specified period of time has elapsed (2 seconds maybe?) and you are not still waiting on results from the previous request. When the completion event fires, update your UI.
Having said that, if there is a lot of data involved, I would find out if there was a way in which you could only retrieve the differences between the last data that you received and the current data (i.e. adds, updates, deletes) and only make those changes to the grid data rather than rebinding every time.
-
You could also use two-way WCF binding and let the server push updates to the client. Depending what constitutes as an update (and if the server itself would be aware) it may be better suited since you'll only get updates when they're necessary.Brad Christie– Brad Christie2012年01月07日 16:13:58 +00:00Commented Jan 7, 2012 at 16:13