Closed bp2008 closed 3 years ago
I think this may fix a similar problem when Using Pmp discovery in Unity
I'm just reviewing this now. I think i might solve it a slightly different way, but i'll base my changes on top of your patch as it's mostly the right approach!
I took some of these changes, but not all of them. Let me know if the current version in master is ok for your needs!
I did the first round of cleanups to give proper synchronous cleanup/shutdown which is also threadsafe.
https://github.com/alanmcgovern/Mono.Nat/pull/32
If you're doing some further testing, i'd appreciate if you tested using that branch as I'll merge that to master in the near future to fully address the issues you uncovered in this PR :)
Thanks. My need for UPnP/NAT-PMP testing has passed for now, but if I ever need to do it again, I'll try and remember to go back to your master branch.
No problem, and thanks for taking the time to push some changes upstream! :D
You're very welcome! Thanks for maintaining this project!
To fix
NatUtility.StopDiscovery()
hanging in a Windows Forms app, I had to add severalConfigureAwait(false)
calls. Along the way to fixing this, I also added code to honor CancellationTokens in a few places they were being ignored. I can't promise there are no unintended consequences to these changes, but I think it should be an overall improvement to reliability.This pull request also includes the same fix I submitted earlier in this unrelated pull request: https://github.com/alanmcgovern/Mono.Nat/pull/29