Timer tick event is not calling

Hi All
I have created a window service and add a timer to fire event after 1 minute.
I installed service and start it then i debug its process in VS 2005 it worked fine and timer event fired automatically. But if donot use debug of VS 2005 and wait for that timer event firing it doesnot fire even after 30 minute it is not firing.

Please help me.

Regards
Imran Zubair




Answer this question

Timer tick event is not calling

  • JohnnyBlade

    I haven't asked you to use any text file, If you have read my previos post that this code should work with some modification. That meant that remove that reading from file and move the Thread.Sleep to the start of the DoWork function.

    Anyhow, I tested the thing in your are getting problem and saw the same behaviour, It's not firing. I don't know why because I have always prefered to use a single thread to work in Windows Service. I have never tried timer in Windows Service before but seeing your question, I did a little experiment which failed to achieve the the goal. I dont know what's reason behind this.

    But I tried that modificaiton about the Threading in Windows service so that it may suite your need.

    Try this if you are interested:

    using System;

    using System.ComponentModel;

    using System.ServiceProcess;

    using System.Threading;

    namespace WindowsService2

    {

    public partial class Service1 : ServiceBase

    {

    private Thread doWorkThread;

    private bool existThread = false;

    public Service1()

    {

    InitializeComponent();

    this.doWorkThread = new Thread(new ThreadStart(DoWork));

    }

    protected override void OnStart(string[] args)

    {

    this.doWorkThread.Start(); // Start The Thread

    }

    protected override void OnStop()

    {

    this.existThread = true;

    }

    private void DoWork()

    {

    if (this.existThread)

    return;

    Thread.Sleep(TimeSpan.FromMilliseconds(2000)); // Wait for 2 Seconds (This is equal to the Timer's Interval Property

    //Do Your work Here.

    ///////////

    }

    }

    }

    It'll behave 100% alike a timer control. (Put the interval of your choice and all other things will go smooth).

    I hope this will help.

    Best Regards,

    Rizwan aka RizwanSharp



  • RonDiamond

    Try this approach, I hope this will better work with a little modification.

    http://forums.microsoft.com/MSDN/showpost.aspx postid=1199368&siteid=1

    Best Regards,

    Rizwan aka RizwanSharp



  • AlexBB

    Hi Rizwan
    Actually i am using timer control and doesnot want to replace it with time setting in config or text file. And in .net 1.0 i have used same timer control which was worked fine but in .net 2.0 it is creating that problem.

    Regards
    Imran Zubair



  • Timer tick event is not calling