Click here to Skip to main content
15,902,275 members
Home / Discussions / C#
   

C#

 
GeneralClass not registered error Pin
Rekha desai20-Nov-03 5:12
sussRekha desai20-Nov-03 5:12 
GeneralRe: Class not registered error Pin
Heath Stewart20-Nov-03 7:20
protectorHeath Stewart20-Nov-03 7:20 
GeneralSuspend Windows... Pin
nzwy1p20-Nov-03 0:28
nzwy1p20-Nov-03 0:28 
GeneralRe: Suspend Windows... Pin
Heath Stewart20-Nov-03 3:17
protectorHeath Stewart20-Nov-03 3:17 
GeneralTimer trouble -timer "dies" Pin
EnkelIk19-Nov-03 21:09
EnkelIk19-Nov-03 21:09 
GeneralRe: Timer trouble -timer "dies" Pin
mhmoud rawas20-Nov-03 0:21
mhmoud rawas20-Nov-03 0:21 
GeneralRe: Timer trouble -timer "dies" Pin
EnkelIk24-Nov-03 21:54
EnkelIk24-Nov-03 21:54 
GeneralRe: Timer trouble -timer "dies" Pin
Heath Stewart20-Nov-03 3:13
protectorHeath Stewart20-Nov-03 3:13 
Several things: if you read the documentation for Start and Stop, they are exactly the same as passing true and false to the Timer.Enabled property, respectively. Don't do both because it's a waste of CPU time.

Second, it is recommended that you don't use GC.Collect. Instead, dispose of the objects in your "[Write to database]" block that implement IDisposable.

Finally: exception handling and stopping / starting timers. What's probably happening is that since you're stopping the timer, writing to the event log, and then performing database functions - which can be volatile - and then starting the timer again, if an exception were to be thrown your time would not be started again! Instead, put your database calls in a try-catch and gracefully catch all exceptions, or add this.vscTimer.Start() to a finally block of a try-catch-finally or try-finally (exceptions are still thrown in the latter block, but finally is always executed regardless of success.

You should also enable auto-logging on the Windows Service by setting ServiceBase.AutoLog to true (of course, your service inherits ServiceBase, so you can set this property on yourself, too).

One more option: don't stop the timer! If you don't stop it, even if the database code throws an exception, the timer will keep running. Besides, lets say all the database code takes 2 seconds and you run this code every 10 minutes. That means that you're shifting time about 4.8 minutes per day! Just let it run, man! Smile | :)

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: Timer trouble -timer "dies" Pin
Xiangyang Liu 刘向阳23-Nov-03 9:09
Xiangyang Liu 刘向阳23-Nov-03 9:09 
GeneralRe: Timer trouble -timer "dies" Pin
Heath Stewart24-Nov-03 4:33
protectorHeath Stewart24-Nov-03 4:33 
GeneralRe: Timer trouble -timer "dies" Pin
Xiangyang Liu 刘向阳24-Nov-03 14:28
Xiangyang Liu 刘向阳24-Nov-03 14:28 
GeneralRe: Timer trouble -timer "dies" Pin
EnkelIk24-Nov-03 22:02
EnkelIk24-Nov-03 22:02 
GeneralProblem while sending mail from windows service using MSMAPI Pin
alexander13219-Nov-03 20:35
alexander13219-Nov-03 20:35 
GeneralRe: Problem while sending mail from windows service using MSMAPI Pin
Heath Stewart20-Nov-03 3:01
protectorHeath Stewart20-Nov-03 3:01 
GeneralRe: Problem while sending mail from windows service using MSMAPI Pin
alexander13220-Nov-03 3:29
alexander13220-Nov-03 3:29 
GeneralRe: Problem while sending mail from windows service using MSMAPI Pin
Heath Stewart20-Nov-03 3:42
protectorHeath Stewart20-Nov-03 3:42 
GeneralRe: Problem while sending mail from windows service using MSMAPI Pin
Xiangyang Liu 刘向阳23-Nov-03 9:27
Xiangyang Liu 刘向阳23-Nov-03 9:27 
GeneralHelp Displaying Unicode String Pin
WorldNomad19-Nov-03 19:19
WorldNomad19-Nov-03 19:19 
GeneralRe: Help Displaying Unicode String Pin
Heath Stewart20-Nov-03 2:51
protectorHeath Stewart20-Nov-03 2:51 
GeneralRe: Help Displaying Unicode String Pin
WorldNomad20-Nov-03 16:41
WorldNomad20-Nov-03 16:41 
GeneralMake control draw on top of other forms Pin
JacksonBrown196019-Nov-03 12:37
JacksonBrown196019-Nov-03 12:37 
GeneralRe: Make control draw on top of other forms Pin
Heath Stewart20-Nov-03 3:55
protectorHeath Stewart20-Nov-03 3:55 
GeneralRe: Make control draw on top of other forms Pin
JacksonBrown196020-Nov-03 5:11
JacksonBrown196020-Nov-03 5:11 
GeneralProblem testing NetworkStream for remote close Pin
ChiPlastique19-Nov-03 12:25
ChiPlastique19-Nov-03 12:25 
GeneralRe: Problem testing NetworkStream for remote close Pin
Kentamanos19-Nov-03 12:53
Kentamanos19-Nov-03 12:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.