44 lines
924 B
C#
44 lines
924 B
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace SCRUM_Timer;
|
|
|
|
public class CountdownTimer
|
|
{
|
|
public TimeSpan ActualTime { get; private set; }
|
|
public bool isRunning;
|
|
private Thread timerThread;
|
|
|
|
public CountdownTimer()
|
|
{
|
|
ActualTime = new TimeSpan(0, 5, 0);
|
|
timerThread = new Thread(TimerTick);
|
|
isRunning = false;
|
|
}
|
|
|
|
public void StartStop()
|
|
{
|
|
if (!isRunning)
|
|
{
|
|
timerThread.Start();
|
|
isRunning = true;
|
|
Console.WriteLine("Timer is running");
|
|
}
|
|
else
|
|
{
|
|
timerThread.Abort();
|
|
isRunning = false;
|
|
Console.WriteLine("Timer is stopped");
|
|
}
|
|
}
|
|
|
|
private void TimerTick()
|
|
{
|
|
while (isRunning)
|
|
{
|
|
ActualTime = -TimeSpan.FromSeconds(1);
|
|
Thread.Sleep(1000);
|
|
Console.WriteLine(ActualTime);
|
|
}
|
|
}
|
|
} |