I'm working on a gui application (C#, .NET Core, WinUI 3) that connects to a remote device. The device acts like a server with a single available connection.
By the app's requirements, I need to periodically poll the device and allow a user to send commands. To solve this,
- I create a single
connection
object (say, a tcp/ip socket) - I start the polling via
pollingTask = Task.Start(polling.PollInfinite)
- In the polling and the user's network operations, the connection singleton is locked (
lock (connection) { connection.send/receive }
).
The scheme above works well when I test it in a local network, so messages to the device does not mess up and the app's UI is not blocked (at least by my experience).
Now I imagine two situations
- A non-local network may have a larger ping
- A user may run the app on a computer with one thread
In each situation... Would the UI blocked? Could the user send commands while polling
waits for the device response?
Also, I'm looking for general recommendations for meeting the app's requirements.
P.S. I'm not experienced with asynchronous programming, but suppose that it should be used anywhere in my app when a network operation happen.