private void Poller(object parameter) { _lastWriteTime = DateTime.MinValue; DateTime currentLastWriteTime = DateTime.MinValue; PollingStatus pollingStatus = (PollingStatus)parameter; while (pollingStatus.Polling) { currentLastWriteTime = GetCurrentLastWriteTime(); if (currentLastWriteTime != DateTime.MinValue) { // might miss a change if a change occurs before it's ran for the first time. if (_lastWriteTime.Equals(DateTime.MinValue)) { _lastWriteTime = currentLastWriteTime; } else { if (_lastWriteTime.Equals(currentLastWriteTime) == false) { _lastWriteTime = currentLastWriteTime; OnChanged(); } } } Thread.Sleep(_pollDelayInMilliseconds); } }
/// <summary> /// <para>Stops watching the configuration file.</para> /// </summary> public virtual void StopWatching() { Thread pollingThread = _pollingThread; if (pollingThread == null) return; lock (_padLockObj) { if (_pollingThread != null) { _pollingStatus.Polling = false; int noOfRetry = 0; while (_pollingThread.IsAlive) { noOfRetry++; Thread.Sleep(100); if (noOfRetry == 5) { _pollingThread.AbortThread(); break; } } if (!_pollingThread.IsAlive) { _pollingStatus = null; _pollingThread = null; } } } }
/// <summary> /// <para>Starts watching the configuration file.</para> /// </summary> public virtual void StartWatching() { Thread pollingThread = _pollingThread; if (pollingThread != null) return; lock (_padLockObj) { if (_pollingThread == null) { ResetWatching(); _pollingStatus = new PollingStatus(true); _pollingThread = new Thread(new ParameterizedThreadStart(Poller)); if (!DoNotUseGlobalQueue) PollNow(); else { _pollingThread.IsBackground = true; _pollingThread.Name = ThreadName; _pollingThread.Start(_pollingStatus); Thread.Sleep(100); } } } }
private void PollNow() { PollingStatus pollingStatus = null; while (true) { pollingStatus = _pollingStatus; //if (!ChoFramework.ShutdownRequested) // ChoQueuedExecutionService.Global.Enqueue<int, PollingStatus>(_pollNow, _pollDelayInMilliseconds, _pollingStatus); if (pollingStatus != null && pollingStatus.Polling) { if (!ChoFramework.ShutdownRequested) { IAsyncResult result = ChoQueuedExecutionService.Global.Enqueue <int, PollingStatus>(_pollNow, _pollDelayInMilliseconds, _pollingStatus); result.AsyncWaitHandle.WaitOne(); Thread.Sleep(_pollDelayInMilliseconds); } else { break; } } else { break; } } }
private void Poller(object parameter) { lastWriteTime = DateTime.MinValue; DateTime currentLastWriteTime = DateTime.MinValue; PollingStatus pollingStatus = (PollingStatus)parameter; while (pollingStatus.Polling) { currentLastWriteTime = GetCurrentLastWriteTime(); if (currentLastWriteTime != DateTime.MinValue) { if (lastWriteTime.Equals(DateTime.MinValue)) { lastWriteTime = currentLastWriteTime; } else { if (lastWriteTime.Equals(currentLastWriteTime) == false) { lastWriteTime = currentLastWriteTime; OnConfigurationChanged(); } } } Thread.Sleep(pollDelayInMilliseconds); } }
private void Poller(object parameter) { DateTime currentLastWriteTime; PollingStatus pollingStatus = (PollingStatus)parameter; if (DoNotUseGlobalQueue) { while (pollingStatus.Polling) { if (!_stopWatching) { currentLastWriteTime = GetCurrentLastWriteTime(); if (_firstTime) { _firstTime = false; _lastUpdatedTimeStamp = currentLastWriteTime; } else { if (_lastUpdatedTimeStamp != currentLastWriteTime) { if (ChoApplication.IsInitialized) { _lastUpdatedTimeStamp = currentLastWriteTime; OnConfigurationChanged(); } } } } Thread.Sleep(_pollDelayInMilliseconds); } } else { if (!_stopWatching) { currentLastWriteTime = GetCurrentLastWriteTime(); if (_firstTime) { _firstTime = false; _lastUpdatedTimeStamp = currentLastWriteTime; } else { if (_lastUpdatedTimeStamp != currentLastWriteTime) { if (ChoApplication.IsInitialized) { _lastUpdatedTimeStamp = currentLastWriteTime; OnConfigurationChanged(); } } } } //if (pollingStatus != null && pollingStatus.Polling) // PollNow(); } }
/// <summary> /// <para>Stops watching the configuration file.</para> /// </summary> public void StopWatching() { lock (_lockObj) { if (_pollingThread != null) { _pollingStatus.Polling = false; _pollingStatus = null; _pollingThread = null; } } }
/// <summary> /// <para>Stops watching the configuration file.</para> /// </summary> public void StopWatching() { lock (lockObj) { if (pollingThread != null) { pollingStatus.Polling = false; pollingStatus = null; pollingThread = null; } } }
/// <summary> /// <para>Starts watching the configuration file.</para> /// </summary> public void StartWatching() { lock (_lockObj) { if (_pollingThread == null) { _pollingStatus = new PollingStatus(true); _pollingThread = new Thread(new ParameterizedThreadStart(Poller)); _pollingThread.IsBackground = true; _pollingThread.Name = this.GetParameter.GroupName; _pollingThread.Start(_pollingStatus); } } }
/// <summary> /// <para>Starts watching the configuration file.</para> /// </summary> public void StartWatching() { lock (lockObj) { if (pollingThread == null) { pollingStatus = new PollingStatus(true); pollingThread = new Thread(new ParameterizedThreadStart(Poller)); pollingThread.IsBackground = true; pollingThread.Name = this.BuildThreadName(); pollingThread.Start(pollingStatus); } } }
private void DisposeWatcher() { _stopWatching = true; Thread pollingThread = _pollingThread; if (pollingThread == null) { return; } lock (_padLockObj) { if (_pollingThread != null) { _pollingStatus.Polling = false; int noOfRetry = 0; while (_pollingThread.IsAlive) { noOfRetry++; Thread.Sleep(100); if (noOfRetry == 5) { _pollingThread.AbortThread(); break; } } if (!_pollingThread.IsAlive) { _pollingStatus = null; _pollingThread = null; } } } }
public void StopWatching() { lock (this.lockObj) { if (this.pollingThread != null) { this.pollingStatus.Polling = false; this.pollingStatus = null; this.pollingThread = null; } } }