/// <summary> /// Stop the update thread. If the update thread is not running, silently does /// nothing. This method returns after the update thread has stopped. /// </summary> public virtual void StopUpdateThread() { UninterruptableMonitor.Enter(syncLock); try { if (updateThread != null) { // this will trigger the thread to terminate if it awaits the lock. // otherwise, if it's in the middle of replication, we wait for it to // stop. updateThread.stop.Signal(); try { updateThread.Join(); } catch (Exception ie) when(ie.IsInterruptedException()) { Thread.CurrentThread.Interrupt(); throw new Util.ThreadInterruptedException(ie); } } updateThread = null; } finally { UninterruptableMonitor.Exit(syncLock); } }
/// <summary> /// Start the update thread with the specified interval in milliseconds. For /// debugging purposes, you can optionally set the name to set on /// <see cref="ThreadJob.Name"/>. If you pass <c>null</c>, a default name /// will be set. /// </summary> /// <exception cref="InvalidOperationException"> if the thread has already been started </exception> public virtual void StartUpdateThread(long intervalInMilliseconds, string threadName) { UninterruptableMonitor.Enter(syncLock); try { EnsureOpen(); if (updateThread != null && updateThread.IsAlive) { throw IllegalStateException.Create("cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); } threadName = threadName is null ? INFO_STREAM_COMPONENT : "ReplicationThread-" + threadName; updateThread = new ReplicationThread(intervalInMilliseconds, threadName, DoUpdate, HandleUpdateException, updateLock); updateThread.Start(); // we rely on isAlive to return true in isUpdateThreadAlive, assert to be on the safe side if (Debugging.AssertsEnabled) { Debugging.Assert(updateThread.IsAlive, "updateThread started but not alive?"); } } finally { UninterruptableMonitor.Exit(syncLock); } }
/// <summary> /// Stop the update thread. If the update thread is not running, silently does /// nothing. This method returns after the update thread has stopped. /// </summary> public virtual void StopUpdateThread() { // this will trigger the thread to terminate if it awaits the lock. // otherwise, if it's in the middle of replication, we wait for it to // stop. if (updateThread != null) updateThread.Stop(); updateThread = null; }
/// <summary> /// Start the update thread with the specified interval in milliseconds. For /// debugging purposes, you can optionally set the name to set on /// <see cref="ReplicationThread.Name"/>. If you pass <c>null</c>, a default name /// will be set. /// </summary> /// <exception cref="InvalidOperationException"> if the thread has already been started </exception> public virtual void StartUpdateThread(long intervalMillis, string threadName) { EnsureOpen(); if (updateThread != null && updateThread.IsAlive) throw new InvalidOperationException("cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); threadName = threadName == null ? INFO_STREAM_COMPONENT : "ReplicationThread-" + threadName; updateThread = new ReplicationThread(intervalMillis, threadName, DoUpdate, HandleUpdateException, updateLock); updateThread.Start(); // we rely on isAlive to return true in isUpdateThreadAlive, assert to be on the safe side Debug.Assert(updateThread.IsAlive, "updateThread started but not alive?"); }
/// <summary> /// Stop the update thread. If the update thread is not running, silently does /// nothing. This method returns after the update thread has stopped. /// </summary> public virtual void StopUpdateThread() { // this will trigger the thread to terminate if it awaits the lock. // otherwise, if it's in the middle of replication, we wait for it to // stop. if (updateThread != null) { try { updateThread.Stop(); } catch (Exception ie) when(ie.IsInterruptedException()) { throw new Util.ThreadInterruptedException(ie); } } updateThread = null; }