{"id":28872,"date":"2019-04-09T00:00:00","date_gmt":"2019-04-08T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/schedulare-attivita-con-hangfire\/"},"modified":"2021-05-20T19:19:24","modified_gmt":"2021-05-20T17:19:24","slug":"how-to-schedule-activities-with-hangfire","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/","title":{"rendered":"How to schedule activities with Hangfire"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"28849\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/0996526a-c073-46d9-9e9a-9f4a82a84d1c-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"0996526a-c073-46d9-9e9a-9f4a82a84d1c\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-28849\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A&nbsp;<em>user story<\/em>&nbsp;has been recently assigned to me. It is required to integrate&nbsp;<strong>Hangfire<\/strong>, and then decide how to create the&nbsp;<em>jobs<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hangfire is a library available for&nbsp;<strong><em>.NET<\/em><\/strong>&nbsp;and&nbsp;<strong><em>.NET Core<\/em><\/strong>, that permits to schedule jobs in&nbsp;<em>background<\/em>&nbsp;with no need of&nbsp;<em>Windows Service<\/em>&nbsp;or other external processes help. Since I was in ignorance of it, I trust completely in its&nbsp;<strong><a href=\"https:\/\/docs.hangfire.io\/en\/latest\/\" target=\"_blank\" rel=\"noreferrer noopener\">documentation<\/a><\/strong>, which seems to be really good. Hangfire\u2019s main components are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Client<\/strong>&nbsp;&#8211; Responsible for jobs creation;<\/li><li><strong>Job Storage<\/strong>&nbsp;&#8211; Provides a persistence service for jobs and related information;<\/li><li><strong>Server<\/strong>&nbsp;&#8211; Recovers data from the storage and processes them.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"324\" data-attachment-id=\"28851\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image1-5-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-5.png?fit=542%2C324&amp;ssl=1\" data-orig-size=\"542,324\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image1-5\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-5.png?fit=542%2C324&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-5.png?resize=542%2C324&#038;ssl=1\" alt=\"\" class=\"wp-image-28851\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-5.png 542w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-5-480x287.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 542px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s step back to the user story\u2019s tasks. To describe my experience, I create a simple application, starting from a template in Visual Studio: specifically, I decided to create an ASP.NET Core Web Application with a&nbsp;<em>Front-end<\/em>&nbsp;made in Angular. The application has a simple Homepage with a&nbsp;<em>button<\/em>. When you click on the button, a counter starts running. We will transform this action into a job that will be scheduled in Hangfire.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"456\" data-attachment-id=\"28853\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image2-4-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2-4.png?fit=930%2C456&amp;ssl=1\" data-orig-size=\"930,456\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image2-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2-4.png?fit=930%2C456&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2-4.png?resize=930%2C456&#038;ssl=1\" alt=\"\" class=\"wp-image-28853\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image2-4.png 930w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image2-4-480x235.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 930px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s assimilate Hangfire in our project by the addiction of the related&nbsp;<em>Nuget&nbsp;<\/em>package.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"177\" data-attachment-id=\"28855\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image3-4-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-4.png?fit=770%2C177&amp;ssl=1\" data-orig-size=\"770,177\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image3-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-4.png?fit=770%2C177&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-4.png?resize=770%2C177&#038;ssl=1\" alt=\"\" class=\"wp-image-28855\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-4.png 770w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-4-480x110.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 770px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the&nbsp;<em>Startup.cs<\/em>, we register Hangfire as service and then we add&nbsp;<em>Hangfire Server&nbsp;<\/em>to the configuration.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ This method gets called by the runtime. Use this method to add services to the container.\npublic void ConfigureServices(IServiceCollection services)\n{\n\u00a0\u00a0\u00a0\u00a0\/\/...some code\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/ Add Hangfire services\n\u00a0\u00a0\u00a0\u00a0services.AddHangfire(s =&gt; s.UseSqlServerStorage(Configuration.GetConnectionString(&quot;HangfireDemo&quot;)));\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/...some code\n}\n\/\/ This method gets called by the runtime. Use this method to configure the HTTP request pipeline.\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env)\n{\n\u00a0\u00a0\u00a0\u00a0\/\/...some code\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/Hangfire\n\u00a0\u00a0\u00a0\u00a0app.UseHangfireServer();\n\u00a0\u00a0\u00a0\u00a0app.UseHangfireDashboard(&quot;\/hangfire&quot;);\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/...some code\n\u00a0\n});\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We can note that, as we register Hangfire, the storage for our jobs will be defined. In order to make it simpler, I decided to use the SQLServer local instance, where a new database has been created (<em>HangfireDemoDB<\/em>) ), but it\u2019s possible to use other storage types too, as Database NoSQL, or&nbsp;<strong>MongoDB<\/strong>&nbsp;or&nbsp;<em>in-memory&nbsp;<\/em>solutions as&nbsp;<strong>Redis<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"305\" height=\"351\" data-attachment-id=\"28858\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image4-4-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-4.png?fit=305%2C351&amp;ssl=1\" data-orig-size=\"305,351\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image4-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-4.png?fit=305%2C351&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-4.png?resize=305%2C351&#038;ssl=1\" alt=\"\" class=\"wp-image-28858\" srcset=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-4.png?w=305&amp;ssl=1 305w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-4.png?resize=261%2C300&amp;ssl=1 261w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Within the file&nbsp;<em>appsettings.json<\/em>&nbsp;a connection string to DB has been defined.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&quot;ConnectionStrings&quot;: {\n\u00a0\u00a0\u00a0\u00a0&quot;HangfireDemo&quot;: &quot;Server=(LocalDb)\\\\MSSQLLocalDB;Database=HangfireDemoDB; Trusted_Connection=True;MultipleActiveResultSets=true&quot;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As the application starts, many different tables will be created and they will contain the jobs and related information, as I already wrote.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"305\" height=\"407\" data-attachment-id=\"28861\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image5-3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?fit=305%2C407&amp;ssl=1\" data-orig-size=\"305,407\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image5-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?fit=305%2C407&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?resize=305%2C407&#038;ssl=1\" alt=\"\" class=\"wp-image-28861\" srcset=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?w=305&amp;ssl=1 305w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?resize=300%2C400&amp;ssl=1 300w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image5-3.png?resize=150%2C200&amp;ssl=1 150w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The click on the button \u201cincrement counter\u201d causes a&nbsp;<em>HTTP PUT<\/em>&nbsp;request, with whom we pass to the Backend, the present value of our counter. Right inside the&nbsp;<em>Controller<\/em>&nbsp;, that manages this request, we must schedule our jobs, whose action would be to increment the counter\u2019s value.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;HttpPut]\n&#x5B;Route(&quot;&#x5B;action]&quot;)]\npublic void SendCurrentCounter(&#x5B;FromBody] Counter currentCounter)\n{\n\u00a0\u00a0\u00a0\u00a0counter.Value = currentCounter.Value;\n\u00a0\u00a0\u00a0\u00a0BackgroundJob.Enqueue(() =&gt; incrementCounter());\n}\n\u00a0\npublic void incrementCounter()\n{\n\u00a0\u00a0\u00a0\u00a0counter.Value++;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The job we are going to schedule is of&nbsp;<strong><em>fire-and-forget<\/em><\/strong>&nbsp;type, the better type for our example, among all types available. With Hangfire, we can schedule jobs with different scheduling types too: as example,&nbsp;<strong><em>delayed jobs<\/em><\/strong>, that are those jobs scheduled after a period of time, or the&nbsp;<strong><em>recurring jobs<\/em><\/strong>, that have to be performed at regular intervals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the configuration of our example, we also insert the Hangfire Dashboard, that is reachable, in this case, to the address:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;host]:&#x5B;port]\/hangfire\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This graphical interface allows us to have a graphic representation of scheduled jobs and provide us many useful information about them, as the jobs, that have been rightly scheduled and those failed. Below we can see the result of the scheduling of ten jobs, both on the dashboard and on DB.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"409\" data-attachment-id=\"28864\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image6-4-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-4.png?fit=1854%2C741&amp;ssl=1\" data-orig-size=\"1854,741\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image6-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-4.png?fit=1024%2C409&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-4.png?resize=1024%2C409&#038;ssl=1\" alt=\"\" class=\"wp-image-28864\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-4-980x392.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-4-480x192.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"584\" data-attachment-id=\"28866\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image7-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1.png?fit=1179%2C672&amp;ssl=1\" data-orig-size=\"1179,672\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image7-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1.png?fit=1024%2C584&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1.png?resize=1024%2C584&#038;ssl=1\" alt=\"\" class=\"wp-image-28866\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1-1024x584.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1-980x559.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image7-1-480x274.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">and on the DB.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"813\" height=\"454\" data-attachment-id=\"28868\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/attachment\/image8-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image8-2.png?fit=813%2C454&amp;ssl=1\" data-orig-size=\"813,454\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image8-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image8-2.png?fit=813%2C454&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image8-2.png?resize=813%2C454&#038;ssl=1\" alt=\"\" class=\"wp-image-28868\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image8-2.png 813w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image8-2-480x268.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 813px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We have just scratched the surface of this topic, Hangfire makes available many other functionalities&nbsp;and is one of the tools can\u2019t miss in your \u201cIT arsenal\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the code on my github to this address:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<a href=\"https:\/\/github.com\/intersect88\/HangfireDemo\" rel=\"nofollow\">https:\/\/github.com\/intersect88\/HangfireDemo<\/a>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">See you next<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s discover together how to perform activities in background with a professional tool<\/p>\n","protected":false},"author":196716251,"featured_media":28849,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637416],"class_list":["post-28872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-asp-net-core-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to schedule activities with Hangfire - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to schedule activities with Hangfire - Blexin\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s discover together how to perform activities in background with a professional tool\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-08T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T17:19:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Genny Paudice\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Genny Paudice\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/\"},\"author\":{\"name\":\"Genny Paudice\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\"},\"headline\":\"How to schedule activities with Hangfire\",\"datePublished\":\"2019-04-08T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:19:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/\"},\"wordCount\":580,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"Asp.net core\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/\",\"name\":\"How to schedule activities with Hangfire - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2019-04-08T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:19:24+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/how-to-schedule-activities-with-hangfire\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to schedule activities with Hangfire\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\",\"name\":\"Genny Paudice\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"caption\":\"Genny Paudice\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/genny-paudiceblexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to schedule activities with Hangfire - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/","og_locale":"en_US","og_type":"article","og_title":"How to schedule activities with Hangfire - Blexin","og_description":"Let\u2019s discover together how to perform activities in background with a professional tool","og_url":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/","og_site_name":"Blexin","article_published_time":"2019-04-08T22:00:00+00:00","article_modified_time":"2021-05-20T17:19:24+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Genny Paudice","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Genny Paudice","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/"},"author":{"name":"Genny Paudice","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973"},"headline":"How to schedule activities with Hangfire","datePublished":"2019-04-08T22:00:00+00:00","dateModified":"2021-05-20T17:19:24+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/"},"wordCount":580,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","keywords":["Asp.net core"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/","url":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/","name":"How to schedule activities with Hangfire - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","datePublished":"2019-04-08T22:00:00+00:00","dateModified":"2021-05-20T17:19:24+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/how-to-schedule-activities-with-hangfire\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to schedule activities with Hangfire"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973","name":"Genny Paudice","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","caption":"Genny Paudice"},"url":"https:\/\/blexin.com\/en\/author\/genny-paudiceblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/0996526a-c073-46d9-9e9a-9f4a82a84d1c.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7vG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716251"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28872"}],"version-history":[{"count":3,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28872\/revisions"}],"predecessor-version":[{"id":31995,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28872\/revisions\/31995"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/28849"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}