0

3秒ごとに起動するように設定されたWebアプリのスケジューラーを作成しました。Console.Write( "bob")を使用してスケジューラーが正しく機能しているかどうかを確認したいのですが、何も起こらず、[デバッグ]ボタンをクリックした後にWebページのみが作成されます。私は間違った方法でテストしていますか、それともスケジューラーが実際に機能していませんか?

これが私が書いたコードです:

namespace Scheduler
{
    public partial class CheckExpireService : ServiceBase
    {
        private CheckExpireJob job;
        private Timer stateTimer;
        private TimerCallback timerDelegate;


        public CheckExpireService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            job = new CheckExpireJob();
            timerDelegate = new TimerCallback(job.CheckExpireApplicants);
            stateTimer = new Timer(timerDelegate, null, 1000, 3000);
        }

        protected override void OnStop()
        {
            stateTimer.Dispose();
        }
    }
}


namespace Scheduler
{
    class CheckExpireJob: ServiceBase
    {
        public void CheckExpireApplicants(object stateObject) {
        Console.Write("bob");
        }
    }
}

前もって感謝します!!

4

1 に答える 1

1

(I was going to leave a comment, but edit and answer are the only things I seem to have available.)

First, I don't think you can run a Windows Service in Debug mode...it has to be compiled and installed as a service and started and stopped with the services manager in Windows. If you have this code somewhere in a web application, it will not work. It needs to be a seperate project.

Second, you can't construct and call a service like this. If you want a service that does something on a timed interval, you need to have the timer and all of its workings within the service.

You can't schedule a web app...it runs when someone visits the page. What is it that you REALLY need to schedule? Regular updates of the data that the web app will pull from?

Need to know more about what you are trying to accomplish to be any help.

于 2012-04-27T20:55:26.370 に答える