I have a window service which plays a sound file at a specified time, so to do that I have taken Timer but it\'s Tick event is never fired, same is working in WinForm applic
try to use other Timer :) here is difference
Try to use the System.Timers.Timer
instead.
this.alarmTimer = new System.Timers.Timer();
The System.Windows.Forms.Timer
- as it names implies - works in Forms applications, but not in something like a NT Service.
I think System.Timers.Timer is a better choice :
Timer _timer = new Timer();
// In miliseconds 60000 = 1 minute
// This timer will tick every 1 minute
_timer.Interval += 6000;
// Activate the timer
_timer.Enabled = true;
// When timer "tick"
_timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
Dont use a System.Windows.FOrms.Timer, use a System.Threading.Timer.
A service is not a form.
Are you sure it's the timer that's the issue? It's extremely unusual for a windows service to access the sound system, (How would you turn it off?) it may be blocked or it may require "interaction with desktop" enabled.
Having said that, TomTom is right, Forms Timers are about being able to Marshal to the UI thread, which you don't have, rather using a Threading timer.