Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

c# - How can I run schedule job with out windows service on server?

I have sent a mail that works locally using asp.net and quartz. It works very well. but it didn't work when I put it on the server. They said that because it is shared hosting, they cannot run it for security reasons. Sql Agent is also not provided as standard. I guess HangFire doesn't use windows service. I could not find how to do it with asp.net web form either.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe someone needs this code for Asp.net webform.

EmailJob Code

public class EmailJob : IJob
{

    public void Execute(IJobExecutionContext context)
    {
        sendmail();
    }

   public void sendMail()
    {
       //send mail code
    }

}

JobScheduler code working 00.00 for every day. you can change what you want.. :)

public class JobScheduler
{
    public static void Start()
    {
        IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
        scheduler.Start();

        IJobDetail job = JobBuilder.Create<EmailJob>().Build();


        ITrigger trigger = TriggerBuilder.Create()
            .WithDailyTimeIntervalSchedule
              (s =>
                 s.WithIntervalInHours(24)
                .OnEveryDay()
                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(00, 00))
                .InTimeZone(TimeZoneInfo.Local)
              )
            .Build();

        scheduler.ScheduleJob(job, trigger);
    }
}

Global.asax start jobscheduler

void Application_Start(object sender, EventArgs e)
    {
        JobScheduler.Start();

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...