开发者

Problem Firing Timer On Windows Service

开发者 https://www.devze.com 2023-03-20 13:30 出处:网络
I am having a problem get code to run through a system timer on a service , well actually no the timer IS firing , however the code below it will not run.

I am having a problem get code to run through a system timer on a service , well actually no the timer IS firing , however the code below it will not run.

    protected override void OnStart(string[] args)
    {
        EventLog.WriteEntry("Service Started");
        //ad 1: handle Elapsed event 
    timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

    //ad 2: set interval to 1 minute (= 60,000 milliseconds)

    timer.Interval = 60000;
    timer.AutoReset = true;
    //ad 3: enabling the timer
    timer.Enabled = true;
    }

    protected override void OnStop()
    {
        timer.Enabled = false;
    }




    private void OnElapsedTime(object source, ElapsedEventArgs e)
         {
            EventLog.WriteEntry("TIMER FIRED");
            string[] filepaths = Directory.GetFiles(path, Filetype);
            string result;

            // Process Each String/File In Directory
            foreach (s开发者_C百科tring s in filepaths)
            {
                for (int i = 0; i < filepaths.Length; i++)
                {
                    //Result Returns Video Name
                    result = Path.GetFileNameWithoutExtension(filepaths[i]);

                    PreformTranslation(filepaths[i], outputPath + result);

                    if (File.Exists(path + result))
                    {
                        MoveVideoFiles(path + result, outputPath + result);
                    }
                }
            }
         }

So i See from the event viewer that it actually sends the "timer Fired" off each minute , but does not precede to run any of the code below. Without the timer in place the code runs as it should, so inititally i just tried calling the method, when that didn't work i just placed the code in the event handler hoping that would change. I think I've already lost when i resort to hope.

0

精彩评论

暂无评论...
验证码 换一张
取 消