protect ConnectToNetwork
@@ -128,7 +128,7 @@ namespace IoTCoreDefaultApp
return msg;
}
- private Dictionary<WiFiAvailableNetwork, WiFiAdapter> networkNameToInfo;
+ private Dictionary<WiFiAvailableNetwork, WiFiAdapter> networkNameToInfo = new Dictionary<WiFiAvailableNetwork, WiFiAdapter>();
private static WiFiAccessStatus? accessStatus;
@@ -188,7 +188,6 @@ namespace IoTCoreDefaultApp
return false;
}
- networkNameToInfo = new Dictionary<WiFiAvailableNetwork, WiFiAdapter>();
List<WiFiAdapter> WiFiAdaptersList = new List<WiFiAdapter>(WiFiAdapters.Values);
foreach (var adapter in WiFiAdaptersList)
{
@@ -283,6 +282,8 @@ namespace IoTCoreDefaultApp
return false;
}
+ try
+ {
var result = await wifiAdapter.ConnectAsync(network, autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual);
//Call redirect only for Open Wifi
@@ -294,6 +295,11 @@ namespace IoTCoreDefaultApp
return (result.ConnectionStatus == WiFiConnectionStatus.Success);
}
+ catch (Exception)
+ {
+ return false;
+ }
+ }
public void DisconnectNetwork(WiFiAvailableNetwork network)
{
@@ -321,6 +327,8 @@ namespace IoTCoreDefaultApp
return false;
}
+ try
+ {
var result = await wifiAdapter.ConnectAsync(
network,
autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual,
@@ -328,6 +336,11 @@ namespace IoTCoreDefaultApp
return (result.ConnectionStatus == WiFiConnectionStatus.Success);
}
+ catch (Exception)
+ {
+ return false;
+ }
+ }
private static async Task<bool> TestAccess()
{
