user4576114
user4576114

Reputation:

Quartz is not working in real server

I have access to db and ftp to my live server. I want to schedule a task. I did a schedule in Quartz.net (ASP.Net C#) and it's working fine in the local server, when I upload it to the server I get no out put. I added a file write command to the top and bottom of my task, those files are writing to the destination. Here is the code I wrote

public partial class saaiTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TestClass t = new TestClass();
        t.method("start");

        ISchedulerFactory factory = new StdSchedulerFactory();
        IScheduler scheduler = factory.GetScheduler();

        IJobDetail job = JobBuilder.Create<TestClass>()
            .WithIdentity("name", "group")
            .Build();

        ITrigger triggerCron = TriggerBuilder.Create()
            .WithCronSchedule("0 0/1 * 1/1 * ? *")
            .StartNow()
            .Build();

        scheduler.ScheduleJob(job, triggerCron);
        scheduler.Start();

        Thread.Sleep(TimeSpan.FromMinutes(10));
        scheduler.Shutdown();

        t.method("stop");
    }
}

public class TestClass : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        this.method("job");
    }

    public void method(string filename)
    {
        StreamWriter file2 = new StreamWriter(HostingEnvironment.MapPath("~\\test\\" + filename + ".txt"), true);
        file2.WriteLine("Write Time : " + DateTime.Now);
        file2.Close();
    }
}

I started the schedule by running this page, I tried adding this to Global.asax. What should I do to start the scheduler in my live server, is it possible to stop the schedule from the server, if so what is the solution ?

Upvotes: 3

Views: 5838

Answers (1)

Saahithyan Vigneswaran
Saahithyan Vigneswaran

Reputation: 7153

I hope this link would give you what you need Simulate a Windows Service using ASP.NET to run scheduled jobs

Quartz uses windows services, use Hangfire instead which doesn't need windows services. This Hangfire, a must for adding background tasks in ASP.NET link would help you get started

Upvotes: 2

Related Questions