I created a scheduler for my web app, which is setup to be fired every 3 seconds. I want to use Console.Write(“bob”) to see if the scheduler is working properly, but nothing happened, only the web page is created after I click the ‘debug’ button. Am I testing the wrong way or the scheduler is indeed not working?
Here’s the code I wrote:
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");
}
}
}
Thanks in advance!!
(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.