public override bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { if (!_enumerator.MoveNext()) { if (_currentIteration == _maxNoOfIteration) { return(false); } else { _currentIteration++; } _enumerator = _enumerable.GetEnumerator(); continue; } if (_match(_enumerator.Current)) { return(true); } } }
public virtual void Start() { ChoGuard.NotDisposed(this); if (_queueProcessingThread != null && _queueProcessingThread.IsAlive) { return; } lock (_padLock) { if (_queueProcessingThread != null && _queueProcessingThread.IsAlive) { return; } try { _queueProcessingThread = new Thread(new ParameterizedThreadStart(QueueProcessingThreadCallback)); _queueProcessingThread.Name = "{0}_{1}Thread".FormatString(_name, this.GetType().Name); _queueProcessingThread.IsBackground = _autoShutdown; _queueProcessingThread.Start(); } catch { _queueProcessingThread = null; throw; } } }
public override bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { if (!_enumerator.MoveNext()) { return(false); } try { if (_currentIndex == 0) { return(true); } if (_currentIndex % (_step + 1) == 0) { return(true); } } finally { _currentIndex++; } } }
public void Start() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { if (_timer != null) { return; } if (_intDueTime.HasValue) { _timer = new Timer(new TimerCallback(OnTimerCallback), _state, _intDueTime.Value, _intPeriod.Value); } else if (_longDueTime.HasValue) { _timer = new Timer(new TimerCallback(OnTimerCallback), _state, _longDueTime.Value, _longPeriod.Value); } else if (_tsDueTime.HasValue) { _timer = new Timer(new TimerCallback(OnTimerCallback), _state, _tsDueTime.Value, _tsPeriod.Value); } else if (_uintDueTime.HasValue) { _timer = new Timer(new TimerCallback(OnTimerCallback), _state, _uintDueTime.Value, _uintPeriod.Value); } else { _timer = new Timer(new TimerCallback(OnTimerCallback), _state, 0, DEFAULT_PERIOD); } } }
//public virtual void OnTimerServiceCallback(T state) //{ // if (_timerServiceCallback != null) // _timerServiceCallback(state); // else // throw new NotSupportedException(); //} public void Pause() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { _isPaused = true; } }
public void StopWatching() { ChoGuard.NotDisposed(this); if (_configurationChangeWatcher != null) { _configurationChangeWatcher.StopWatching(); } }
public void Release() { ChoGuard.NotDisposed(this); if (Interlocked.Decrement(ref _count) == _maxCount - 1) { _event.Set(); } }
public void Start(ChoConsoleProgressorStart consoleProgressorStart, ChoAsyncCallback callback, object state, int timeout) { ChoGuard.NotDisposed(this); int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0); if (isStarted == 1) { return; } Interlocked.CompareExchange(ref _stopRequested, 0, 1); lock (ChoConsole.SyncRoot) { ChoConsole.Clear(); ChoConsole.ClearKeys(); IChoAsyncResult result = ChoConsole.OutputQueuedExecutionService.Enqueue(() => { _location = WriteNSavePosition(_msg + " "); _statusMsgLocation = new ChoPoint(_consolePercentageProgressorSettings.ProgressBarMarginX, _location.Y + 1); WriteSpinner("/"); }); result.AsyncWaitHandle.WaitOne(); } Action <ChoConsoleSpinProgressor> wrappedFunc = delegate { _threadToKill = Thread.CurrentThread; try { while (true) { if (_stopRequested == 1) { break; } ChoConsole.WriteLine(GetNextSpinChar().ToString(), _location, _foregroundColor, _backgroundColor); bool retValue = consoleProgressorStart(this, state); if (!retValue) { break; } } } catch (ThreadAbortException) { Thread.ResetAbort(); } }; _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsoleSpinProgressor>(wrappedFunc, this); }
public void Continue() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { _isPaused = false; _resumeEvent.Set(); } }
public void Stop() { ChoGuard.NotDisposed(this); _waitHandle.Set(); Thread.Sleep(100); if (_idleThread.IsAlive) { _idleThread.AbortThread(); } }
public virtual void Enqueue(int priority, IChoQueuedMsgServiceObject <T> msgQObject) { if (_stoppingService) { return; } ChoGuard.NotDisposed(this); CheckState(); _queue.Enqueue(priority, msgQObject); }
public override bool Wait(int millisecondsTimeout) { ChoGuard.NotDisposed(this); ChoGuard.NotDisposed(_barrier); bool retVal = _barrier.RevSemaphore.WaitOne(millisecondsTimeout); _waitSuccess = true; return(retVal); }
public bool WaitOne(TimeSpan timeout, bool exitContext) { ChoGuard.NotDisposed(this); if (Interlocked.Increment(ref _count) == _maxCount) { return(_event.WaitOne(timeout, exitContext)); } return(true); }
//public virtual void OnTimerServiceCallback(T state) //{ // if (_timerServiceCallback != null) // _timerServiceCallback(state); // else // throw new NotSupportedException(); //} public void Pause() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { if (_timer != null) { _paused = true; _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); } } }
public void Stop() { ChoGuard.NotDisposed(this); lock (_padLock) { Thread thread = _thread; if (thread != null) { _eventTerminate.Set(); thread.Join(); } } }
public void Start() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { if (!_timerThread.IsAlive) { _timerThread.Start(); } else { _isStopped = false; _resumeEvent.Set(); } } }
public override bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { if (!_enumerator.MoveNext()) { return(false); } if (_match(_enumerator.Current)) { return(true); } } }
public virtual void Enqueue(IChoQueuedMsgServiceObject <T> msgQObject) { if (_stoppingService) { return; } ChoGuard.NotDisposed(this); CheckState(); if (_queue.Count >= _maxSize) { return; } //_queue.Enqueue(0, msgQObject); _queue.Enqueue(msgQObject); }
public bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { if (_currentIndex == 0) { return(false); } else { _currentIndex++; if (_match(Current)) { return(true); } } } }
public void Stop() { ChoGuard.NotDisposed(this); lock (_padLock) { Thread thread = _thread; try { if (thread != null && thread.IsAlive) { _eventTerminate.Set(); thread.Join(); _thread = null; } } catch { } } }
public override bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { _currentIndex++; if (_enumerator != null) { if (!_enumerator.MoveNext()) { return(false); } } else { if (_listCount == 0) { return(false); } if (_currentIndex == _listCount - 1) { return(false); } if (_currentIndex < _startIndex) { continue; } } if ((_currentIndex - _startIndex) % _step == 0) { if (_match(Current)) { return(true); } } } }
public void WriteData(T target) { ChoGuard.ArgumentNotNullOrEmpty(target, "Target"); ChoGuard.NotDisposed(this); //using (Mutex mutex = new Mutex(false, ChoMutexHelper.GetName(_name))) //{ // mutex.WaitOne(); using (MemoryMappedViewStream stream = mf.CreateViewStream()) { if (_msgFormatter == ChoMsgFormatter.Binary) { ChoObject.Serialize(stream, target); } else { ChoObject.XmlSerialize(stream, target); } } _event.Set(); //} }
public void Start() { ChoGuard.NotDisposed(this); if (IsStarted) { return; } lock (_padLock) { if (IsStarted) { return; } _eventTerminate.Reset(); _thread = new Thread(new ThreadStart(MonitorThread)); _thread.IsBackground = true; _thread.Start(); } }
public override bool MoveNext() { ChoGuard.NotDisposed(this); while (true) { if (_currentIndex == 0) { return(false); } if (_currentIndex == _startIndex - _count - 1) { return(false); } _currentIndex--; if (_match(Current)) { return(true); } } }
public void Continue() { ChoGuard.NotDisposed(this); lock (DisposableLockObj) { if (_timer != null) { if (_paused) { _paused = false; if (_intDueTime.HasValue) { _timer.Change(0, _intPeriod.Value); } else if (_longDueTime.HasValue) { _timer.Change(0, _longPeriod.Value); } else if (_tsDueTime.HasValue) { _timer.Change(TimeSpan.Zero, _tsPeriod.Value); } else if (_uintDueTime.HasValue) { _timer.Change(0, _uintPeriod.Value); } else { _timer.Change(0, DEFAULT_PERIOD); } } } } }
public override void Stop() { ChoGuard.NotDisposed(this); //Console.WriteLine(String.Format("Stopping {0} asynchronous execution service...", Name)); _queuedMsgService.Dispose(); }
public override void Start() { ChoGuard.NotDisposed(this); _queuedMsgService.Start(); }
public void Start(ChoConsolePercentageProgressorStart consolePercentageProgressorStart, ChoAsyncCallback callback, object state, int timeout) { ChoGuard.NotDisposed(this); //if (_isStarted) return; int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0); if (isStarted == 1) { return; } Interlocked.CompareExchange(ref _stopRequested, 0, 1); lock (ChoConsole.SyncRoot) { ChoConsole.Clear(); ChoConsole.ClearKeys(); IChoAsyncResult result = ChoConsole.OutputQueuedExecutionService.Enqueue(() => { _location = WriteNSavePosition(_msg + " "); _statusMsgLocation = new ChoPoint(_consolePercentageProgressorSettings.ProgressBarMarginX, _location.Y + 1); WritePercentage("[0%]"); }); result.AsyncWaitHandle.WaitOne(); SetPercentageComplete(MinPercentage); } Action <ChoConsolePercentageProgressor, int> wrappedFunc = delegate { _threadToKill = Thread.CurrentThread; try { int percentage = MinPercentage; int retPercentage = MinPercentage; while (retPercentage < MaxPercentage) { if (_stopRequested == 1) { break; } retPercentage = consolePercentageProgressorStart(this, percentage, state); if (percentage >= retPercentage) { throw new ChoConsoleException("Returned percentage '{0}' value <= running percentage '{1}' value. It may leads to infinite loop.".FormatString(retPercentage, percentage)); } else { percentage = retPercentage; } lock (ChoConsole.SyncRoot) { SetPercentageComplete(retPercentage); } } } catch (ThreadAbortException) { Thread.ResetAbort(); } }; //try //{ // ChoAPM.InvokeMethod(wrappedFunc, new object[] { this, MinPercentage }, timeout); //} //catch (Exception ex) //{ // ErrorOccured(this, new ChoExceptionEventArgs(ex)); //} _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsolePercentageProgressor, int>(wrappedFunc, this, MinPercentage, callback, state, timeout); }
public void Start() { ChoGuard.NotDisposed(this); _idleThread.Start(); }
public void Start(ChoConsolePercentageProgressorStartEx consolePercentageProgressorStart, ChoAsyncCallback callback, object state, int timeout) { ChoGuard.NotDisposed(this); int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0); if (isStarted == 1) { return; } Interlocked.CompareExchange(ref _stopRequested, 0, 1); lock (ChoConsole.SyncRoot) { ChoConsole.Clear(); ChoConsole.ClearKeys(); _consoleCoordinate = new ConsoleCoordinate((short)(Console.CursorLeft + _consolePercentageProgressorSettings.ProgressBarMarginX), (short)(Console.CursorTop + _consolePercentageProgressorSettings.ProgressBarMarginY)); ShowProgress(MinPercentage, _msg); } Action <ChoConsolePercentageProgressorEx, int> wrappedFunc = delegate { _threadToKill = Thread.CurrentThread; try { int percentage = MinPercentage; int retPercentage = MinPercentage; while (retPercentage < MaxPercentage) { if (_stopRequested == 1) { break; } Tuple <int, string> retValue = consolePercentageProgressorStart(this, percentage, state); retPercentage = retValue.Item1; if (percentage >= retPercentage) { throw new ChoConsoleException("Returned percentage '{0}' value <= running percentage '{1}' value. It may leads to infinite loop.".FormatString(retPercentage, percentage)); } else { percentage = retPercentage; } ShowProgress(retPercentage, retValue.Item2); } } catch (ThreadAbortException) { Thread.ResetAbort(); } finally { Console.WriteLine(); Console.WriteLine(); Console.ResetColor(); } }; _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsolePercentageProgressorEx, int>(wrappedFunc, this, MinPercentage, callback, state, timeout); }