Now sends netstate update request 3 seconds after a network change event. Added method for initiating a request with delay.

systray
MCARDLE Sean M 2016-11-18 22:32:23 -08:00
parent 6628030186
commit 022009680b
1 changed files with 18 additions and 2 deletions

View File

@ -7,9 +7,12 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.ServiceProcess;
using System.Net.NetworkInformation;
using WifiSitter;
using WifiSitter.Model;
using WifiSitterGui.Helpers;
using XDMessaging;
namespace WifiSitterGui.ViewModel
@ -42,7 +45,9 @@ namespace WifiSitterGui.ViewModel
private void Intitialize() {
// Get NetState
RequestNetworkState();
// Intermittent network state polling
_netstateCheckTimer = new System.Timers.Timer();
_netstateCheckTimer.AutoReset = true;
@ -50,6 +55,10 @@ namespace WifiSitterGui.ViewModel
_netstateCheckTimer.Elapsed += (o, e) => { RequestNetworkState(); };
_netstateCheckTimer.Start();
// Connection state changed event handler setup
NetworkChange.NetworkAvailabilityChanged += (o, e) => { RequestNetworkState(3 * 1000); };
NetworkChange.NetworkAddressChanged += (o, e) => { RequestNetworkState(3 * 1000); };
Trace.WriteLine(String.Format("WifiSitter service msg channel: {0}", ServiceChannelName));
}
@ -67,6 +76,7 @@ namespace WifiSitterGui.ViewModel
return _wsIpc;
}
}
public MainWindowViewModel WindowVM {
get { if (_windowVM == null) {
@ -78,6 +88,8 @@ namespace WifiSitterGui.ViewModel
}
public int IconSize { get { return 40; } }
internal string ServiceChannelName {
get {
if (_serviceChannel == null) {
@ -97,7 +109,11 @@ namespace WifiSitterGui.ViewModel
#region methods
private void RequestNetworkState () {
public void RequestNetworkState(int Delay) {
Task.Delay(Delay).ContinueWith((task) => { RequestNetworkState(); }, TaskScheduler.FromCurrentSynchronizationContext());
}
public void RequestNetworkState () {
if (!String.IsNullOrEmpty(ServiceChannelName)) {
try {
Trace.WriteLine("Checking for network state.");