MarcusW.VncClient
MarcusW.VncClient copied to clipboard
Migrate from using Threads to using Tasks for receiving and sending data
This PR changes the background tasks from using threads to instead use tasks.
The reason for this change is that using Threads using ThreadStart will keep the thread reserved for that background job, even though that job might just wait for input. That means no-one else can use that thread which might lead to depleting the thread pool if you had multiple VNC connections open. It thus isn't very scalable. The second benefit of not using threads is that exceptions can't be handled in threads at all, which leads to unhandleable problems like in #25.
The only issue with my implementation is that any exceptions thrown get silently eaten until the Task is awaited (which in my case happens when StopSendLoopAsync()
is called). I don't really know of a good solution for this, however feedback is welcome. It might also be small enough to be considered a "won't fix™".
If you have any questions about my implementation, please reach out.
Closes #25
Very nice, thank you! Will have a look when I'm back from vacation.