Simple timer start and stop from console

The name of the pictureThe name of the pictureThe name of the pictureClash 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");








share|improve this question

















  • 2




    VTC can you tell me what else you are looking for?
    – paparazzo
    Apr 3 at 16:11
















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");








share|improve this question

















  • 2




    VTC can you tell me what else you are looking for?
    – paparazzo
    Apr 3 at 16:11












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");








share|improve this question













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");










share|improve this question












share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer





















  • I will look into game loops.
    – paparazzo
    Apr 10 at 5:20










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.






share|improve this answer





















  • I will look into game loops.
    – paparazzo
    Apr 10 at 5:20














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.






share|improve this answer





















  • I will look into game loops.
    – paparazzo
    Apr 10 at 5:20












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.






share|improve this answer













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.







share|improve this answer













share|improve this answer



share|improve this answer











answered Apr 10 at 2:42









Phil DeVeau

662




662











  • 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




I will look into game loops.
– paparazzo
Apr 10 at 5:20












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?