Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Restart #15

Open
glenneroo opened this issue Aug 15, 2021 · 1 comment
Open

Feature request: Restart #15

glenneroo opened this issue Aug 15, 2021 · 1 comment

Comments

@glenneroo
Copy link

It would be useful in some special cases to be able to restart a running timer from the beginning. Maybe this functionality already exists? Here is my attempt, but maybe I missed something:

/// <summary>
/// Restarts a running or paused timer.
/// </summary>
public void Restart() 
{
    if (this.isDone) 
    {
        return;
    }

    this._timeElapsedBeforePause = null;
    this._startTime = this.GetWorldTime();
    this.isCompleted = false;
}
@eckhardEhm
Copy link

Afaik after completion the timer cannot be reused.
Changing .isCompleted will not give you the result you seek as the timer already has been removed from the TimerManager List of Timers.

So if the timer is completed, I start a new one.
If it is still running you can reset the time.

    /// <summary>
    /// Restart a Timer by Setting the Starttime and LastUpdatetime to Timer.GetWorldTime(). Returns true if it had not Completed, false if the Timer is Completed.
    /// </summary>
    public bool Restart()
    {
        if (!this.isCompleted)
        {
            this._startTime = this.GetWorldTime();
            this._lastUpdateTime = this._startTime;
            return true;
        }
        return false;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants