Ed Glogowski
Ed Glogowski

Reputation: 79

UWP App using Windows.Devices.WiFi

I am writing a UWP app using the Windows.Devices.WiFi to basically get a lists of networks. Everything was working fine when I retrieved the information a time or two. However, I wanted to put the code into a timer so I can report regularly. Once I did this, I got "an attempt was made to establish a session to a network server, but there are already too many sessions established to that server."

I am not sure what is establishing connections as I am just trying to read the information. I am not even calling the ConnectAsync calls.

Can anyone help me out? I need to know what to dispose, or close, etc.

Update: Further analysis, I am finding that the call to FindAllAdaptersAsync multiple times is causing this issue.

Upvotes: 4

Views: 696

Answers (2)

Eugene A. Grebenyuk
Eugene A. Grebenyuk

Reputation: 1

This happens with WiFiAdapter.FromIdAsync too.

"already too many sessions established to that server", on the 20th call.

After n calls of WiFiAdapter.FromIdAsync, do GC.Collect(). It helps.

n must be < 20. For example, 10.

Upvotes: 0

Ed Glogowski
Ed Glogowski

Reputation: 79

I decided to cache up the list of adapters by only calling FindAllAdaptersAsync once. Thanks for the idea Henk. This seemed to fix my issue for now. However, I think that it is a bug with FindAllAdaptersAsync. I would think you should be able to call this as much as you like, unless maintaining the network connection is necessary every time. Or at least a way to free them up.

Upvotes: 1

Related Questions