| | |
Timer in windows service
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 23
Reputation:
Solved Threads: 0
I'm trying to make basic windows service that should write into application event log some text once every minute. So I'm using a timer. But the Tick event doesn't fire.. I've tried all kinds of timer1.start() or timer1.enabled=true ... but nothing works. Everything with service itself is ok- I mean it can be installed, started and onStart() and onStop() it writes event log (also custom, not only the windows default, so the writing itself works..)
So here's the code:
I'd appreciate any help.
Could the problem be in timer properties suck as modifiers: public, or generate members- true?
I'm using Visual Studio 2005
So here's the code:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Text; using System.Windows.Forms; using System.Timers; using System.Threading; namespace SERVICE2 { public partial class SERVICE2 : ServiceBase { public SERVICE2() { InitializeComponent(); } protected override void OnStart(string[] args) { timer1.Enabled = true; string src = "Test_Service_2"; string lg = "Application"; string evnt = "SERVICE2 started!"; if (!EventLog.SourceExists(src)) EventLog.CreateEventSource(src, lg); EventLog.WriteEntry(src, evnt); timer1.Start(); } protected override void OnStop() { string src2 = "Test_Service_2"; string lg2 = "Application"; string evnt2 = "SERVICE2 stopped!"; if (!EventLog.SourceExists(src2)) EventLog.CreateEventSource(src2, lg2); EventLog.WriteEntry(src2, evnt2); timer1.Stop(); timer1.Enabled = false; } private void timer1_Tick(object sender, EventArgs e) { string sSource; string sLog; string sEvent; sSource = "Test_Service_2"; sLog = "Application"; sEvent = "Timer TICK"; if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog); EventLog.WriteEntry(sSource, sEvent); EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning, 234); } } }
Could the problem be in timer properties suck as modifiers: public, or generate members- true?
I'm using Visual Studio 2005
![]() |
Similar Threads
- problem with windows service (C#)
- would like some help understanding server timer. (ASP.NET)
- help needed Svchoms1at (Viruses, Spyware and other Nasties)
- Trojan Horse virus svcihos1at.exe (Viruses, Spyware and other Nasties)
Other Threads in the C# Forum
- Previous Thread: Help Please
- Next Thread: word a hyperlink then appear menus !!! how??
Views: 4408 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





