Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Microsoft.Toolkit.Uwp.Connectivity/Network/NetworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,11 @@ namespace Microsoft.Toolkit.Uwp.Connectivity
/// </summary>
public class NetworkHelper
{
/// <summary>
/// Private singleton field.
/// </summary>
private static NetworkHelper _instance;

/// <summary>
/// Event raised when the network changes.
/// </summary>
public event EventHandler NetworkChanged;

/// <summary>
/// Gets public singleton property.
/// </summary>
public static NetworkHelper Instance => _instance ?? (_instance = new NetworkHelper());

/// <summary>
/// Gets instance of <see cref="ConnectionInformation"/>.
/// </summary>
public ConnectionInformation ConnectionInformation { get; } = new ConnectionInformation();

/// <summary>
/// Initializes a new instance of the <see cref="NetworkHelper"/> class.
/// </summary>
Expand All @@ -52,6 +37,19 @@ protected NetworkHelper()
NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChanged;
}

/// <summary>
/// Gets public singleton property.
/// </summary>
public static NetworkHelper Instance { get; } = new NetworkHelper();

/// <summary>
/// Gets instance of <see cref="ConnectionInformation"/>.
/// </summary>
public ConnectionInformation ConnectionInformation { get; }

/// <summary>
/// Checks the current connection information and raises <see cref="NetworkChanged"/> if needed.
/// </summary>
private void UpdateConnectionInformation()
{
lock (ConnectionInformation)
Expand All @@ -69,6 +67,9 @@ private void UpdateConnectionInformation()
}
}

/// <summary>
/// Invokes <see cref="UpdateConnectionInformation"/> when the current network status changes.
/// </summary>
private void OnNetworkStatusChanged(object sender)
{
UpdateConnectionInformation();
Expand Down