I am using WiFiAdapter class on a c# application to connect remote access point.
The PC I am working on has a WiFi interface and a wired LAN interface.
The application scans the available AP to find a specified SSID,
public async Task<WiFiAvailableNetwork> Scan(String SSID)
{
WiFiAvailableNetwork network = null;
var access = await WiFiAdapter.RequestAccessAsync();
var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
if (result.Count >= 1)
{
wifiAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);
await wifiAdapter.ScanAsync();
//sp.Children.Clear();
foreach (var item in wifiAdapter.NetworkReport.AvailableNetworks)
{
if (SSID.Equals(item.Ssid))
network = item;
}
}
return network;
}
Once it had found the network I connect to this using password credentials:
private async Task<bool> Connect(WiFiAvailableNetwork network, String password)
{
WiFiReconnectionKind reconnectionKind = WiFiReconnectionKind.Automatic;
WiFiConnectionResult result = null;
if (network.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211)
{
result = await wifiAdapter.ConnectAsync(network, reconnectionKind);
}
else
{
var credential = new PasswordCredential();
if (!string.IsNullOrEmpty(password))
{
credential.Password = password;
}
result = await wifiAdapter.ConnectAsync(network, reconnectionKind, credential).AsTask();
}
return (result.ConnectionStatus == WiFiConnectionStatus.Success);
}
This method always works when I am working on the PC which runs the application.
When I am connected via remote Desktop to the PC which runs the application and the remote desktop connection exploits the wired interface, this method sometimes works for a while but at a certain moment I can not connect any access point. The ConnectAsyn method returns ConnectionStatus.NetworkNotAvailable. However I can connect the same AP using the Windows interface.
In this situation the only solution I found to make ConnectAsyn work again is to logout from my account and login again.
It looks like a bug of this class in this very particular situation which unfortunately is the standard mode in which my application should work.