joker77 Posted June 15, 2007 Posted June 15, 2007 Hi there, I'm having trouble starting a very simple Windows Service I created with a System.Threading.Timer. The code is a basic windows service project, with the following lines of note: using System.Threading; public partial class TimerClass: ServiceBase { private Timer _timer; public TimerClass() { InitializeComponent(); } protected override void OnStart(string[] args) { TimerCallback callback = new TimerCallback(OnTimedEvent); _timer = new Timer(callback, null, 10000, 60000); } protected override void OnStop() { // Stop Timer } private void OnTimedEvent(Object stateInfo) { // Do something } } } When I try to start the service, I get the following error: "The TimerService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs." If I remove the 2 lines in the OnStart method, the service starts fine. I've looked around on the internet, and from what I was reading the System.Threading.Timers is the one to use in a Windows Service rather than System.Timers.Timer (obviously the Windows forms one can't be used). Quote What if the Hokey-Pokey IS what it's all about?
Administrators PlausiblyDamp Posted June 17, 2007 Administrators Posted June 17, 2007 If you write to the event log before and after starting the timer does both entries get logged? Also if you write to the log in the callback does it ever fire? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.