C
C#9mo ago
Juicy

❔ SignalR for real-time REST api data in WPF?

Hey, Im working on a hobby WPF application that needs to consume a rest api for real-time updates on game camera positions. Since the camera position data is always updating I want my wpf app to reflect those updates in realtime....would signalR be a good solution or is api polling good enough? Or anyone has any other recommendations for a straightforward way to ensure the client recieves near real-time updates from the rest api? Thanks!
29 Replies
Pobiega
Pobiega9mo ago
SignalR would be a lot nicer than polling
Juicy
Juicy9mo ago
oh hey pobiega! hope you doing good :D about that btw, does signalR work with any rest api? endpoint looks like this: https://127.0.0.1:2999/replay/render works to do a get request but I dont think its a websocket, if thats needed
Pobiega
Pobiega9mo ago
Uh no, you need SignalR on the server AND client sides. Its a "wrapper" around websockets.
Juicy
Juicy9mo ago
Ahh.. damn I dont think it would work then Whats my next best option?
Pobiega
Pobiega9mo ago
in SigR, the server pushes data to the client
Juicy
Juicy9mo ago
ah I see
Pobiega
Pobiega9mo ago
if you cant modify the server, then its polling only
Juicy
Juicy9mo ago
Alright appreciate the help thanks btw, I suppose multiple threads is the way to go here? if I have muliple endpoints to get data from
Pobiega
Pobiega9mo ago
that seems overkill
Juicy
Juicy9mo ago
hmm
Pobiega
Pobiega9mo ago
just use async task
Juicy
Juicy9mo ago
even if its like every 50 miliseconds update?
Pobiega
Pobiega9mo ago
yes
Juicy
Juicy9mo ago
ok im gonna give a go
Pobiega
Pobiega9mo ago
periodictimer with proper use of async await and it should be fine
Juicy
Juicy9mo ago
ok that makes me think about one thing though, why await something that I know will always update/run in the background?
Pobiega
Pobiega9mo ago
wdym
Juicy
Juicy9mo ago
if I want real time data
Pobiega
Pobiega9mo ago
I sense a grave misunderstanding of how async/await and tasks work here
Juicy
Juicy9mo ago
yea probably i was just thinking if i wanted something that updates continiously that i had to run it in the background or something
Pobiega
Pobiega9mo ago
not really, but you could do that this is for updating a WPF app, right?
Juicy
Juicy9mo ago
yep
Pobiega
Pobiega9mo ago
I'd probably build this with some reactive elements so your WPF app subscribes to updates from the observable and the "background task" polls the APIs and pushes data to the observable when available
Juicy
Juicy9mo ago
wouldnt i get threading issues like cross thread exception or what its called if i use tasks
Pobiega
Pobiega9mo ago
thats exactly what we are trying to avoid by using IObservable
Juicy
Juicy9mo ago
ahhh okay okay ill try with it
Pobiega
Pobiega9mo ago
https://www.youtube.com/watch?v=6yjl_h7-WYA is a pretty good video on how to think about reactive
Juicy
Juicy9mo ago
awesome thanks
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.