Fixed null errors when service isn't running.

systray
Sean McArdle 2016-11-21 14:27:34 -08:00
parent 7bb46addb7
commit d912745622
1 changed files with 4 additions and 3 deletions

View File

@ -49,16 +49,17 @@ namespace WifiSitterGui.ViewModel
} }
public List<SimpleNic> Nics { get { return NetState.Nics; } } public List<SimpleNic> Nics { get { return NetState?.Nics; } }
public string ServiceState { public string ServiceState {
get { get {
try { if (_sc == null) _sc = new ServiceController("WifiSitter"); } ServiceControllerStatus status;
try { if (_sc == null) _sc = new ServiceController("WifiSitter"); status = _sc.Status; }
catch { return "No Service"; } catch { return "No Service"; }
_sc.Refresh(); _sc.Refresh();
switch (_sc.Status) { switch (status) {
case ServiceControllerStatus.Running: case ServiceControllerStatus.Running:
return "Running"; return "Running";
case ServiceControllerStatus.Stopped: case ServiceControllerStatus.Stopped: