Click here to Skip to main content
15,889,034 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cuz he's a C# wizard, has to be a twist... Pin
Jeff Varszegi20-Nov-03 14:24
professionalJeff Varszegi20-Nov-03 14:24 
GeneralRe: Cuz he's a C# wizard, has to be a twist... Pin
eggie520-Nov-03 16:14
eggie520-Nov-03 16:14 
GeneralRe: Cuz he's a C# wizard, has to be a twist... Pin
Nick Parker23-Nov-03 6:22
protectorNick Parker23-Nov-03 6:22 
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 
Hi all.

I have a implemented a Window Service which includes a timer. The timer
"ticks" every five minutes, and writes an entry to a database plus
enters a line into an eventlog.

Unfortunatelly this timer does not seem fully reliable as the service
occasionally just stop writing to both the database and the eventlog.
Sometimes this happens when it has been running for just a few hours,
other times when it has been going for several days. Is there a known
limitation in timers? Or is there some internal or external event that
might cause the timer to stop?

Since the timer does not 'die' at the same tick each time it is very
hard to try to debug or something. The code snippets below is pretty straight
forward, I hope you can follow it and that it may give you some clue as
to what is going wrong here.

Do you think it would help to implement a second timer that executes say every
ten hours, which creates a new instance of the first timer? That of
course would leave me at the mercy of the second timer and in the case
where an external event causes the first timer to stop it will most
certainly also cause the second timer to stop...

Thanks
/EnkelIk

public class MyService : System.ServiceProcess.ServiceBase
{
private Timer vscTimer=null;

public MyService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

//Create eventlog
if(!System.Diagnostics.EventLog.SourceExists("MyServiceLogSource"))
System.Diagnostics.EventLog.CreateEventSource("MyServiceLogSource","MyServiceLog");

eventLog.Source = "MyServiceLogSource";
eventLog.Log="MyServiceLog";

double interval=300000;
vscTimer = new Timer(interval);
vscTimer.Elapsed += new ElapsedEventHandler( this.ServiceTimer_Tick );
}
...
[ Auto generated code for initializing and disposing
process ]
...

/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
//Start timer
vscTimer.AutoReset=true;
vscTimer.Enabled=true;
vscTimer.Start();
}

private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{

this.vscTimer.Stop();
eventLog.WriteEntry("Timer event!");

[Write to database]

//Tried to do something about the huge memory consumption...
GC.Collect();

//Restart timer
this.vscTimer.Start();
}
}
GeneralRe: Timer trouble -timer &quot;dies&quot; Pin
mhmoud rawas20-Nov-03 0:21
mhmoud rawas20-Nov-03 0:21 
GeneralRe: Timer trouble -timer &quot;dies&quot; Pin
EnkelIk24-Nov-03 21:54
EnkelIk24-Nov-03 21:54 
GeneralRe: Timer trouble -timer &quot;dies&quot; Pin
Heath Stewart20-Nov-03 3:13
protectorHeath Stewart20-Nov-03 3:13 
GeneralRe: Timer trouble -timer "dies" Pin
Xiangyang Liu 刘向阳23-Nov-03 9:09
Xiangyang Liu 刘向阳23-Nov-03 9:09 
GeneralRe: Timer trouble -timer &quot;dies&quot; Pin
Heath Stewart24-Nov-03 4:33
protectorHeath Stewart24-Nov-03 4:33 
GeneralRe: Timer trouble -timer &quot;dies&quot; Pin
Xiangyang Liu 刘向阳24-Nov-03 14:28
Xiangyang Liu 刘向阳24-Nov-03 14:28 
GeneralRe: Timer trouble -timer &quot;dies&quot; 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 

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.