private async void Watcher()
        {
            while (!disposedValue)
            {
                // Can we talk to the server?
                serverIsOnline = ServerPinging();

                // Is the DB Cache available?
                cacheIsAvailable = DBCacheFunctions.CacheUpToDate(serverIsOnline);

                // Get status based on values of server online and cache mode.
                var status = GetWatchdogStatus();
                if (status != currentWatchdogStatus)
                {
                    currentWatchdogStatus = status;
                    OnStatusChanged(new WatchdogStatusEventArgs(currentWatchdogStatus));
                }

                if (serverIsOnline)
                {
                    //Fire tick event to update server datatime.
                    OnWatcherTick(new WatchdogTickEventArgs(GetServerTime()));
                }

                CheckForCacheRebuild();

                await Task.Delay(watcherInterval);
            }
        }
 public void StartWatcher()
 {
     watcherTask = new Task(() => Watcher(), TaskCreationOptions.LongRunning);
     watcherTask.Start();
     if (inCachedMode)
     {
         currentWatchdogStatus = WatchdogConnectionStatus.CachedMode;
         OnStatusChanged(new WatchdogStatusEventArgs(WatchdogConnectionStatus.CachedMode));
     }
 }
 private void CheckForCacheRebuild()
 {
     if (currentWatchdogStatus == WatchdogConnectionStatus.Online)
     {
         if (!cacheIsAvailable)
         {
             OnRebuildCache(new EventArgs());
         }
         if (previousWatchdogStatus == WatchdogConnectionStatus.CachedMode || previousWatchdogStatus == WatchdogConnectionStatus.Offline)
         {
             OnRebuildCache(new EventArgs());
         }
     }
     previousWatchdogStatus = currentWatchdogStatus;
 }
 public WatchdogStatusEventArgs(WatchdogConnectionStatus connectionStatus)
 {
     this.ConnectionStatus = connectionStatus;
 }