Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k 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 Reply

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();

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...