C
C#15mo 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
Pobiega15mo ago
SignalR would be a lot nicer than polling
Juicy
JuicyOP15mo 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
Pobiega15mo ago
Uh no, you need SignalR on the server AND client sides. Its a "wrapper" around websockets.
Juicy
JuicyOP15mo ago
Ahh.. damn I dont think it would work then Whats my next best option?
Pobiega
Pobiega15mo ago
in SigR, the server pushes data to the client
Juicy
JuicyOP15mo ago
ah I see
Pobiega
Pobiega15mo ago
if you cant modify the server, then its polling only
Juicy
JuicyOP15mo 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
Pobiega15mo ago
that seems overkill
Juicy
JuicyOP15mo ago
hmm
Pobiega
Pobiega15mo ago
just use async task
Juicy
JuicyOP15mo ago
even if its like every 50 miliseconds update?
Pobiega
Pobiega15mo ago
yes
Juicy
JuicyOP15mo ago
ok im gonna give a go
Pobiega
Pobiega15mo ago
periodictimer with proper use of async await and it should be fine
Juicy
JuicyOP15mo ago
ok that makes me think about one thing though, why await something that I know will always update/run in the background?
Pobiega
Pobiega15mo ago
wdym
Juicy
JuicyOP15mo ago
if I want real time data
Pobiega
Pobiega15mo ago
I sense a grave misunderstanding of how async/await and tasks work here
Juicy
JuicyOP15mo 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
Pobiega15mo ago
not really, but you could do that this is for updating a WPF app, right?
Juicy
JuicyOP15mo ago
yep
Pobiega
Pobiega15mo 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
JuicyOP15mo ago
wouldnt i get threading issues like cross thread exception or what its called if i use tasks
Pobiega
Pobiega15mo ago
thats exactly what we are trying to avoid by using IObservable
Juicy
JuicyOP15mo ago
ahhh okay okay ill try with it
Pobiega
Pobiega15mo ago
https://www.youtube.com/watch?v=6yjl_h7-WYA is a pretty good video on how to think about reactive
Juicy
JuicyOP15mo ago
awesome thanks
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server