Simple timer start and stop from console
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
Just a simple timer application for review. Stop and start the timer from the command line.
The plan is to use this in a poker application to fold out a player if they don't act after a time period (call the clock on them). I was trying to use async await but it did not seem like the right tool for this.
MyTimer myTimer = new MyTimer();
while (true)
string readLine = Console.ReadLine();
if (readLine == "stop")
myTimer.TimerStop();
else if (readLine == "start")
myTimer.TimerStart();
else if (readLine == "q")
Environment.Exit(0);
.
public class MyTimer
private System.Timers.Timer aTimer = new System.Timers.Timer();
private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
Debug.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
Console.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
public void TimerStop()
aTimer.Enabled = false;
Console.WriteLine("aTimer.Enabled = false");
public void TimerStart()
aTimer.Enabled = true;
Console.WriteLine("aTimer.Enabled = true");
public MyTimer()
aTimer.Interval = 2000;
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
// Have the timer fire repeated events (true is the default)
aTimer.AutoReset = true;
// Start the timer
aTimer.Enabled = true;
Debug.WriteLine("aTimer.Enabled");
Console.WriteLine("aTimer.Enabled");
c# .net timer
add a comment |Â
up vote
2
down vote
favorite
Just a simple timer application for review. Stop and start the timer from the command line.
The plan is to use this in a poker application to fold out a player if they don't act after a time period (call the clock on them). I was trying to use async await but it did not seem like the right tool for this.
MyTimer myTimer = new MyTimer();
while (true)
string readLine = Console.ReadLine();
if (readLine == "stop")
myTimer.TimerStop();
else if (readLine == "start")
myTimer.TimerStart();
else if (readLine == "q")
Environment.Exit(0);
.
public class MyTimer
private System.Timers.Timer aTimer = new System.Timers.Timer();
private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
Debug.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
Console.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
public void TimerStop()
aTimer.Enabled = false;
Console.WriteLine("aTimer.Enabled = false");
public void TimerStart()
aTimer.Enabled = true;
Console.WriteLine("aTimer.Enabled = true");
public MyTimer()
aTimer.Interval = 2000;
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
// Have the timer fire repeated events (true is the default)
aTimer.AutoReset = true;
// Start the timer
aTimer.Enabled = true;
Debug.WriteLine("aTimer.Enabled");
Console.WriteLine("aTimer.Enabled");
c# .net timer
2
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Just a simple timer application for review. Stop and start the timer from the command line.
The plan is to use this in a poker application to fold out a player if they don't act after a time period (call the clock on them). I was trying to use async await but it did not seem like the right tool for this.
MyTimer myTimer = new MyTimer();
while (true)
string readLine = Console.ReadLine();
if (readLine == "stop")
myTimer.TimerStop();
else if (readLine == "start")
myTimer.TimerStart();
else if (readLine == "q")
Environment.Exit(0);
.
public class MyTimer
private System.Timers.Timer aTimer = new System.Timers.Timer();
private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
Debug.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
Console.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
public void TimerStop()
aTimer.Enabled = false;
Console.WriteLine("aTimer.Enabled = false");
public void TimerStart()
aTimer.Enabled = true;
Console.WriteLine("aTimer.Enabled = true");
public MyTimer()
aTimer.Interval = 2000;
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
// Have the timer fire repeated events (true is the default)
aTimer.AutoReset = true;
// Start the timer
aTimer.Enabled = true;
Debug.WriteLine("aTimer.Enabled");
Console.WriteLine("aTimer.Enabled");
c# .net timer
Just a simple timer application for review. Stop and start the timer from the command line.
The plan is to use this in a poker application to fold out a player if they don't act after a time period (call the clock on them). I was trying to use async await but it did not seem like the right tool for this.
MyTimer myTimer = new MyTimer();
while (true)
string readLine = Console.ReadLine();
if (readLine == "stop")
myTimer.TimerStop();
else if (readLine == "start")
myTimer.TimerStart();
else if (readLine == "q")
Environment.Exit(0);
.
public class MyTimer
private System.Timers.Timer aTimer = new System.Timers.Timer();
private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
Debug.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
Console.WriteLine("The Elapsed event was raised at 0", e.SignalTime);
public void TimerStop()
aTimer.Enabled = false;
Console.WriteLine("aTimer.Enabled = false");
public void TimerStart()
aTimer.Enabled = true;
Console.WriteLine("aTimer.Enabled = true");
public MyTimer()
aTimer.Interval = 2000;
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
// Have the timer fire repeated events (true is the default)
aTimer.AutoReset = true;
// Start the timer
aTimer.Enabled = true;
Debug.WriteLine("aTimer.Enabled");
Console.WriteLine("aTimer.Enabled");
c# .net timer
edited Apr 3 at 16:11
asked Apr 3 at 14:57
paparazzo
4,8131730
4,8131730
2
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11
add a comment |Â
2
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11
2
2
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Why aren't you inheriting from Timer it's not a sealed class and is disposable (and I believe must be disposed).
public class PokerTimer : Timer
public PokerTimer() : this(2000)
public PokerTimer(double interval) : base(interval)
AutoReset = true;
Elapsed += OnTimedEvent;
protected override void Dispose(bool disposing)
//clean up anything you need to here or remove this override.
base.Dispose(disposing);
All that being said, you said this is for a game where you want to time out players so you might want to look a bit into game loops and managing state in such a loop.
I will look into game loops.
â paparazzo
Apr 10 at 5:20
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Why aren't you inheriting from Timer it's not a sealed class and is disposable (and I believe must be disposed).
public class PokerTimer : Timer
public PokerTimer() : this(2000)
public PokerTimer(double interval) : base(interval)
AutoReset = true;
Elapsed += OnTimedEvent;
protected override void Dispose(bool disposing)
//clean up anything you need to here or remove this override.
base.Dispose(disposing);
All that being said, you said this is for a game where you want to time out players so you might want to look a bit into game loops and managing state in such a loop.
I will look into game loops.
â paparazzo
Apr 10 at 5:20
add a comment |Â
up vote
2
down vote
accepted
Why aren't you inheriting from Timer it's not a sealed class and is disposable (and I believe must be disposed).
public class PokerTimer : Timer
public PokerTimer() : this(2000)
public PokerTimer(double interval) : base(interval)
AutoReset = true;
Elapsed += OnTimedEvent;
protected override void Dispose(bool disposing)
//clean up anything you need to here or remove this override.
base.Dispose(disposing);
All that being said, you said this is for a game where you want to time out players so you might want to look a bit into game loops and managing state in such a loop.
I will look into game loops.
â paparazzo
Apr 10 at 5:20
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Why aren't you inheriting from Timer it's not a sealed class and is disposable (and I believe must be disposed).
public class PokerTimer : Timer
public PokerTimer() : this(2000)
public PokerTimer(double interval) : base(interval)
AutoReset = true;
Elapsed += OnTimedEvent;
protected override void Dispose(bool disposing)
//clean up anything you need to here or remove this override.
base.Dispose(disposing);
All that being said, you said this is for a game where you want to time out players so you might want to look a bit into game loops and managing state in such a loop.
Why aren't you inheriting from Timer it's not a sealed class and is disposable (and I believe must be disposed).
public class PokerTimer : Timer
public PokerTimer() : this(2000)
public PokerTimer(double interval) : base(interval)
AutoReset = true;
Elapsed += OnTimedEvent;
protected override void Dispose(bool disposing)
//clean up anything you need to here or remove this override.
base.Dispose(disposing);
All that being said, you said this is for a game where you want to time out players so you might want to look a bit into game loops and managing state in such a loop.
answered Apr 10 at 2:42
Phil DeVeau
662
662
I will look into game loops.
â paparazzo
Apr 10 at 5:20
add a comment |Â
I will look into game loops.
â paparazzo
Apr 10 at 5:20
I will look into game loops.
â paparazzo
Apr 10 at 5:20
I will look into game loops.
â paparazzo
Apr 10 at 5:20
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191170%2fsimple-timer-start-and-stop-from-console%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
VTC can you tell me what else you are looking for?
â paparazzo
Apr 3 at 16:11