c# - Exiting from timer based polling loop -


I have a console app that runs something on demand reporting in the webpage. The app starts, runs some scaling, starts a (1 second) timer, and blocks on the console. Readline (); Statement (I mean goods in a service instead, but this is for another day)

There is no exception to this now, so if there is a choice against SQL Server Or goes down the network hiccup, it just crashes, I am now trying to implement a raw exception handling. Inside the timer-callback I have filled the SQL-query within a trycatch. If it fails, it handles exceptions by logging, a failure increases and starts the timer again. If it fails for more than 5 times, I want to get it out of the app How can I stop / leave the console app that is blocked by a readline statement?

A code in the code:

I think a more elegant solution is one Block with reset event. When the timer callsback to a point, it assumes that it has not been worked to do now.

  Fixed readonly manual reset reset asset = new manual reset reset (incorrect); Static zero main (string [] arg) {var t = new timer (timercodeback, empty, -1, 1000); T. Change (0, 1000); Reset.WaitOne (); // The application will sit here until the timer tells him not to continue. } Private Static Zero timer callback {object state} {try {// do stuff. } Hold (exception e) {failCounter ++; If (failCounter> 5) {reset.Set (); // Release the reset event and the application will exit, return; }}}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -