Need example to setup HangFire in web application

Hi
I am new with HangFire ,I need to implement recurring jobs in my web application for sending mails to user .
may be daily ,weekly or monthly mails .My requirement like bellow
We know about SQL Server jobs where we can specify a Stored Procedure into the job and set timing for the the job .
My application running in shared server so I don’t have full access to SQL Server.In my situation I need

  1. Create a job with HangFire from my application’s interface ,where I can specify various parameter for the job.
  2. At the time when a job start running I execute some SQL query and do a specific work .
    How could I do this please give me some idea.

Have you tried to find an answer yourself? The problem is too generic.

I read http://docs.hangfire.io/en/latest/tutorials/send-email.html.
what I am understand from this post is.mails send immediately after create comment.
but I want a scheduler ,
suppose I schedule a task for running on every Sunday .on this task I specify a SQL Server stored Procedure with some parameter.when task will start the SP will execute from this sp I will get some email address and mail content and finally the content mailed to the email address.this schedule mast run automatically background in my application on scheduled time.

can you please give some idea how I achieve this?

I download from https://github.com/HangfireIO/Hangfire and set Hangfire/samples/MvcSample/ as start up but it shows The resource cannot be found.

Kuntal, hi! :smiley:
if i understand, what you need is a recurring job, scheduled job is only for one time, for example:
I want send e-mail right now, i will enqueue:

BackgroundJob.Enqueue(() => sendMail());

I want send e-mail only one time after one day, i will use the schedule job.

BackgroundJob.Schedule(() => sendMail(), TimeSpan.FromDays(1));

I want send e-mail every day or week or whatever, i will use one recurring job.

RecurringJob.AddOrUpdate(() => sendMail(), Cron.Daily/monthly);

Remember that every method above accepts one expression with action, so, you can enqueue schedule or add diferent classes and tasks :smile:

1 Like