C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Have windows service run specific day & time weekly Posted by bbcompent1 on 14 Mar 2013 at 1:35 PM
Hello experts, I'm looking for help here so bear with me. Due to circumstances I have no control over, I cannot use Windows Task Scheduler for this. I have to use a windows service with a System.Timers.Timer call. What I'd like to do is have the service run on a specific day of the week at a specific time that I specify in my app.config file. Here's the code I have so far and I suspect I'm going to need a try/catch block.

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            _timer = new System.Timers.Timer();
            _timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            _timer.Enabled = true;
            _timer.Interval = ReadTime;
            _timer.Start();
        }

        protected override void OnStop()
        {

        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _lastRun = DateTime.Now;
            _timer.Stop();
            _thread = new Thread(new ThreadStart(APFImporter));
            _thread.Name = "DoImport";
            _thread.Start();
            _timer.Start();
        }





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.