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); }
public void Start(ChoConsolePercentageProgressorStartEx consolePercentageProgressorStart, int timeout) { Start(consolePercentageProgressorStart, null, null, timeout); }
public void Start(ChoConsolePercentageProgressorStartEx consolePercentageProgressorStart, ChoAsyncCallback callback, object state) { Start(consolePercentageProgressorStart, callback, state, Timeout.Infinite); }
public void Start(ChoConsolePercentageProgressorStartEx consolePercentageProgressorStart) { Start(consolePercentageProgressorStart, Timeout.Infinite); }