-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopWatch.cs
More file actions
73 lines (66 loc) · 1.97 KB
/
StopWatch.cs
File metadata and controls
73 lines (66 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LnDCSharpProj1
{
class StopWatch
{
private DateTime _startTime { get; set; }
private DateTime _stopTime { get; set; }
private bool _currentlyRunning { get; set; }
private TimeSpan _duration { get; set; }
public void Start()
{
if (!_currentlyRunning)
{
_currentlyRunning = true;
_startTime = DateTime.Now;
}
else
{
throw new InvalidOperationException("Stopwatch running. Hit stop before hitting start again.");
}
}
public void Stop()
{
if (_currentlyRunning)
{
_currentlyRunning = false;
_stopTime = DateTime.Now;
}
//var interval = Interval();
//Console.WriteLine("\r\n Duration was: {0}", interval.ToString());
Console.WriteLine("\r\n Duration was: {0}", Interval());
}
public TimeSpan Interval()
{
_duration = _stopTime - _startTime;
return _duration;
}
public void Runner(int keyValue)
{
switch (keyValue)
{
case 1:
try
{
Start();
break;
}
catch (InvalidOperationException)
{
Console.WriteLine("Stopwatch running. Hit stop before hitting start again.");
break;
}
case 2:
Stop();
break;
case 3:
Environment.Exit(0);
break;
}
}
}
}