BACKGROUND TASKS in ASP NET Core | Getting Started With ASP.NET Core Series

Поделиться
HTML-код
  • Опубликовано: 27 авг 2024
  • Hello, Background tasks are those that run in the background without interfering with the primary process. In ASP NET Core background tasks are implemented as Hosted Services. This allows us to perform tasks outside of the main web thread, determine changes to data in a database, and also long-running tasks to process messages from the queue, etc.
    In this video let's learn how to create and run a task in the background in ASP.NET Core applications. We will learn how to use the BackgroundService class, how to register it to work with the ASP NET Application. We will also see how the IHostedService interface works along with the BackgroundService and also the different Dependency Injection models it supports.
    Additional Watching
    📹Dependency Injection - • DEPENDENCY INJECTION i...
    📹Logging - • LOGGING in ASP.NET Cor...
    📹ASP NET Core Series - • ASP.NET Core
    Come say hi! ✋
    🌍 Blog - rahulpnath.com/
    ✉ Subscribe to my Newsletter - www.rahulpnath...
    🐦Twitter - / rahulpnath
    📸Instagram - / rahulpnath
    🎥 Recording Setup and Workflow - www.rahulpnath...
    Make sure to SUBSCRIBE to the channel. THANK YOU for helping me grow this channel !!

Комментарии • 189

  • @BM-jy6cb
    @BM-jy6cb Год назад +1

    I love the way you just get down to it in your videos. No waffle, but all the detail needed as a jumping off point. Excellent. Thank you.

    • @RahulNath
      @RahulNath  Год назад

      Awesome! Thank you! Hope you are enjoying the full series bit.ly/asp-net-core-series

  • @BM-jy6cb
    @BM-jy6cb Год назад

    Now 23k subscribers, but this channel deserves so much more!

  • @shashikantpawar7069
    @shashikantpawar7069 3 года назад +2

    Please smile a bit ...u crossed 5k😃😃. Congratulations

    • @RahulNath
      @RahulNath  3 года назад

      Thank you Shashikant! Once the camera is on I always forget to smile 😀 (But otherwise I do). With time I hope I will get better at this.

  • @keerthang5557
    @keerthang5557 3 года назад +4

    Excellent Tutorial Rahul, eagerly waiting for part 2!

    • @RahulNath
      @RahulNath  3 года назад +2

      Glad you like it Keerthan and thank you for this video suggestion!

  • @TellaTrix
    @TellaTrix 3 года назад +1

    Superb ! I been facing this problem lot a time. i was not able to inject scoped and transient dependency into singleton. It's too late to know but finally i got my answer. Keep tuned us.

  • @anuragnigam55
    @anuragnigam55 2 года назад +5

    Great content 👍
    The simplicity with which ur going in deep about the topic is amazing

    • @RahulNath
      @RahulNath  2 года назад

      Thank you Anurag! Feel free to let know if you have topic suggestions.

  • @thegaribovv
    @thegaribovv Год назад

    Thanks man, I love your explanation because your are not skipping the boundary cases

    • @RahulNath
      @RahulNath  Год назад

      Glad it was helpful! Hope you are enjoying the full series bit.ly/asp-net-core-series

  • @sachinichathurika9507
    @sachinichathurika9507 3 года назад +2

    Simple and very clear tutorial. Thank you for the great information.

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you Sachini. Do check out the full series here ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP
      I am sure you will like them too! Do let me know in case you get to watch them 😀

  • @shanmuka16
    @shanmuka16 Год назад +1

    Guys let's encourage this channel, tremendous content ❤❤

    • @RahulNath
      @RahulNath  Год назад

      Thank you for the love Shanmukh! Hope you are enjoying the series bit.ly/asp-net-core-series

  • @shovonku
    @shovonku Год назад +1

    Your presentation style is very simple and to the point. Keep up the good work, Rahul.

    • @RahulNath
      @RahulNath  Год назад +1

      Glad you like it. Hope you are enjoying the series bit.ly/asp-net-core-series

  • @atulsingh29
    @atulsingh29 2 года назад

    I'm new to .net core and this problem held me for two days, can't thank you enough 🙏

    • @RahulNath
      @RahulNath  2 года назад +1

      Great to hear Atul! The full ASP Series is here, I am sure you will like them bit.ly/asp-net-core-series

    • @atulsingh29
      @atulsingh29 2 года назад

      @@RahulNath I'm already on it. ⭐⭐⭐⭐⭐

    • @RahulNath
      @RahulNath  2 года назад

      @@atulsingh29 Do drop in if any topic suggestions and feedback 😀👍

  • @efeamioku3220
    @efeamioku3220 2 года назад +2

    I believe this tutorial will help me implement the MS Azure Service Bus Queue as a background service and via IServiceProvider Dependency Injection use repository pattern scoped service to save queue messages to my entityframework SQL Server DB which I will be able to read via my API controller and display to a frontend via API calls using react js. I hope this works...

    • @efeamioku3220
      @efeamioku3220 2 года назад

      Yes, It worked.
      Thanks...

    • @RahulNath
      @RahulNath  2 года назад +1

      Glad to hear that! Thank you Efe 😀

  • @pramod.kulkarni9607
    @pramod.kulkarni9607 Год назад +1

    Amazing Tutorial Rahul.

    • @RahulNath
      @RahulNath  Год назад +1

      Glad you found it useful. The full series is here bit.ly/asp-net-core-series

  • @girmamoges941
    @girmamoges941 Год назад

    Excellent presentation by providing first level easy to understand examples, you are my vote !!!

    • @RahulNath
      @RahulNath  Год назад

      Wow, thank you! Glad you are finding it useful and hope you are liking the series bit.ly/asp-net-core-series

  • @xbenchers1116
    @xbenchers1116 3 года назад

    One of my favorite on RUclips.
    Thank you Sir for the great explanation.

    • @RahulNath
      @RahulNath  3 года назад

      So nice of you. And you can call me Rahul 😀

  • @northshorepx
    @northshorepx Год назад

    Excellent Video!!! Thank you

    • @RahulNath
      @RahulNath  Год назад

      You are welcome! Hope you are enjoying the series bit.ly/asp-net-core-series

  • @hadirezaee7292
    @hadirezaee7292 3 года назад +1

    like always, short, simple and usefull

  • @deivamanidhandabani9505
    @deivamanidhandabani9505 2 года назад +1

    Great Lesson Rahul keep doing the same.

    • @RahulNath
      @RahulNath  2 года назад +1

      Glad you like it - The full series for ASP is here bit.ly/asp-net-core-series

    • @deivamanidhandabani9505
      @deivamanidhandabani9505 2 года назад

      @@RahulNath Could you please explain concurrent collections in C# or send me the link if you have already done the videos.
      Thanks

  • @sufyannisar
    @sufyannisar 3 года назад +1

    Simple and to the Point! Great Tutorial!

    • @RahulNath
      @RahulNath  3 года назад

      Glad you liked it Sufyan! do check out the full playlist here ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP

  • @parwejp
    @parwejp 3 года назад +1

    Nice. Thank you. Unit test cases on background services as well next time. Will share nuget packages on which videos could be created. I forgot about that.

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you and good idea - will try and add testing too in it.

  • @nirajchandrajoshi
    @nirajchandrajoshi Год назад

    Great presentation and complete information in one tutorial... great job.

    • @RahulNath
      @RahulNath  Год назад

      Glad you loved it Niraj! Do check out the full series here bit.ly/asp-net-core-series

  • @hamadsherazi6896
    @hamadsherazi6896 Год назад

    Rahul its a great video. I saw each sec enjoying the content

    • @RahulNath
      @RahulNath  Год назад

      Glad to hear that Hamad. Sure that you will enjoy the full series then bit.ly/asp-net-core-series

  • @rushanthannelson513
    @rushanthannelson513 Год назад

    Thanks, Rahul; your content is always meaningful and applicable to real solutions. Keep up the great work!! Can you make one with scheduled tasks in background services, please?

  • @praveenthakur6908
    @praveenthakur6908 Год назад

    Great explanation Rahul👍👍👍

    • @RahulNath
      @RahulNath  Год назад

      Glad you like it Praveen. Hope you are enjoying the series bit.ly/asp-net-core-series

  • @dsfgato
    @dsfgato 2 года назад

    Such a great content, Rahul!! You're helping me so much with these tutorials. Greetings from Sao Paulo (BR).. cheers

    • @RahulNath
      @RahulNath  2 года назад

      Happy to hear that Douglas! Hope you are enjoying the series bit.ly/asp-net-core-series

  • @khaiquocpham7747
    @khaiquocpham7747 Год назад

    Thank you. The content you make is very easy to understand. Hope you will make more videos

    • @RahulNath
      @RahulNath  Год назад

      Glad you like it. The full ASP series is here ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP

  • @sonalirane4667
    @sonalirane4667 2 года назад +1

    Hi Rahul,
    Amazing video, Can you do a video on reading from database when hosted service starts

    • @RahulNath
      @RahulNath  2 года назад

      Sure happy to - Can you elaborate on your use case, to get some more idea.

  • @bloopers2967
    @bloopers2967 3 года назад +2

    Very well explained, can you please make video on logging in asp.net core and generic, non generic collections in asp.net core

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you 😀 For logging ruclips.net/video/dxBlBltEDRs/видео.html
      Does that help? What specifically are you looking for with collections?

    • @bloopers2967
      @bloopers2967 3 года назад +2

      @@RahulNath like how to use non- generic collections in a real world scenario

    • @RahulNath
      @RahulNath  3 года назад +1

      @@bloopers2967 Mmm that is interesting. I usually don't use that much. What scenario are you using non-generic currently for?

    • @bloopers2967
      @bloopers2967 3 года назад +1

      @@RahulNath 😂😂for solving competitive coding questions

    • @RahulNath
      @RahulNath  3 года назад +1

      @@bloopers2967 Haha ok, one more reason to hate such questions 😂🤣

  • @jackReme
    @jackReme 2 года назад

    Thanks a lot! Great content!

    • @RahulNath
      @RahulNath  2 года назад

      Glad you liked it Jack! The full ASP series is here bit.ly/asp-net-core-series

  • @lamhongbac
    @lamhongbac 7 месяцев назад

    Cảm ơn bạn!

  • @abhishekks6782
    @abhishekks6782 3 года назад +1

    waiting for In Part 2, please give example with some real time examples.

    • @RahulNath
      @RahulNath  3 года назад +1

      Yes, it's on the list! Thank you for the prompt 😀

  • @aravindmaestro1492
    @aravindmaestro1492 3 года назад

    Really helpful.... thanks for uploading some great .net contents..easily understandable...waiting for more such content . Thanks Rahul 😊

    • @RahulNath
      @RahulNath  3 года назад

      Thank you Aravind. Do check out the full series here if you haven't already ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP
      Feel free to let know if you have specific topic suggestions.

  • @ivanpesenti1138
    @ivanpesenti1138 3 года назад

    As usual amazing video Rahul. Thanks for your work and time 😄

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you Ivan! These comments make it worth my time, thank you for watching.

  • @Latif127
    @Latif127 2 года назад

    Very helpful tutorial. Thank you.

    • @RahulNath
      @RahulNath  2 года назад

      Glad it was helpful Abdul!

  • @manjinderbajwa1468
    @manjinderbajwa1468 2 года назад +1

    Excellent keep it up

    • @RahulNath
      @RahulNath  2 года назад

      Thanks a lot! Hope you are liking the series bit.ly/asp-net-core-series

  • @pratikkapadia560
    @pratikkapadia560 2 года назад

    Good one Rahul, if possible please make video on reading from database when hosted service starts, e.g persistent queue.
    But really like your videos

    • @RahulNath
      @RahulNath  2 года назад

      Thats a good suggestion Pratik. I will add that to my list. Glad you like the videos

  • @ksdvishnukumar
    @ksdvishnukumar 3 года назад

    As usual explained very well Rahul...Thanks a ton bro...👍

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you 😀 So happy these help and for letting me know.

  • @christiantobler7628
    @christiantobler7628 2 года назад

    Great video and very clear explanation !

    • @RahulNath
      @RahulNath  2 года назад

      Glad you enjoyed it Christian! Do check out the full ASP Series here bit.ly/asp-net-core-series

  • @harmeetchandok7824
    @harmeetchandok7824 3 года назад +1

    Thanks for this video

    • @RahulNath
      @RahulNath  3 года назад

      Most welcome Harmeet. Do check out the other videos in this series ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP

  • @expertreviews1112
    @expertreviews1112 2 года назад

    That is an excellent video… really really loved it…thnxx

    • @RahulNath
      @RahulNath  2 года назад

      Glad you liked it! Hope you have checked the full series bit.ly/asp-net-core-series

  • @jamesthompson2122
    @jamesthompson2122 3 года назад

    Always helpful and informative! Get some rest though, I saw the time on your build as 5:02 am! :)

    • @RahulNath
      @RahulNath  3 года назад +4

      Glad you like it and thank you for the lovely caring comment. I record all my videos during that time (4-5) 😀 (That's when house is least noisy).
      Wrote about it here if you are interested. twitter.com/rahulpnath/status/1393813849933897737?s=20

  • @navaneethakrishnan1532
    @navaneethakrishnan1532 Год назад

    nice Explanation Rahul

    • @RahulNath
      @RahulNath  Год назад

      Happy you liked it. Do check out the full series here bit.ly/asp-net-core-series

  • @shafiq.hussain.cscore
    @shafiq.hussain.cscore 8 месяцев назад

    Excellent

    • @RahulNath
      @RahulNath  8 месяцев назад

      Thank you so much 😀Hope you are liking the series bit.ly/asp-net-core-series

  • @ElyinAnuarSarriaMontenegro
    @ElyinAnuarSarriaMontenegro 11 месяцев назад

    Hola buenas
    Un vídeo de worker services sería de mucha ayuda
    Saludos

  • @haroonahmad731
    @haroonahmad731 2 года назад

    Very helpful

    • @RahulNath
      @RahulNath  2 года назад

      Glad it helped - Do check out the full series here bit.ly/asp-net-core-series Hope you like them

  • @diegomelgar2696
    @diegomelgar2696 Год назад +1

    Hi Rahul, thanks for your video!!
    In scenarios where the application is abruptly closed, does it exists a workaround how to handle those abruptly closings?

    • @RahulNath
      @RahulNath  Год назад +1

      It's best to use external queues for critical processing and avoid the background tasks for this as you might loose information. What is your scenario you are using this for?

    • @diegomelgar2696
      @diegomelgar2696 Год назад +1

      @@RahulNath what type of external queues do you refer?
      Is a hypothetical scenario of thousand of data to process daily, maybe for example financial institution usually process thousands of records to process loans.
      I was thinking of batch data split in multiple jobs/tasks ?

    • @RahulNath
      @RahulNath  Год назад +1

      @@diegomelgar2696Azure Service Bus Queue, AWS SNS, SQS , Rabbit MQ etc depending on where and how your application is hosted/managed. I have some introduction to this in my Messaging series here ruclips.net/p/PL59L9XrzUa-ku74pfBcy4f3tigwfzGUrG
      For critical processing I wouldn't depend on Background Tasks.

    • @diegomelgar2696
      @diegomelgar2696 Год назад

      @@RahulNath thanks, will check on that!

  • @my4127
    @my4127 2 года назад

    You are so awesome! Thank you!

    • @RahulNath
      @RahulNath  2 года назад

      You are so welcome! Hope you are enjoying the full series here bit.ly/asp-net-core-series

  •  2 года назад

    Good job with the tutorial, could you create some on how to use the QUARTZ library in net core, since the ones that are currently there are very confusing and I think you would make them much easier to understand.

    • @RahulNath
      @RahulNath  2 года назад +1

      Glad you like the video and Great suggestion! I will add this to my list. I have a blog post from a while back here using Quartz in case it helps www.rahulpnath.com/blog/windows-service-using-topshelf-quartz-and-autofac/

  • @tobbyechonga2461
    @tobbyechonga2461 2 года назад

    Thank you very helpful.

    • @RahulNath
      @RahulNath  2 года назад

      Glad it was helpful Tobby! Do check out the full series here ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP

  • @MrSachintelalwar
    @MrSachintelalwar 2 года назад

    Another great video! I knew about Background service but did not know the limitation you demoed. Thank you for pointing that.
    Also, You mentioned that there is a new video coming for exception handling for Background services, can you please add a link for that?.

    • @RahulNath
      @RahulNath  2 года назад

      Glad it was helpful Sachin! Unfortunately I did not get to that video. Are you facing any particular issues? I might look to work on that video soon.

    • @MrSachintelalwar
      @MrSachintelalwar 2 года назад +1

      @@RahulNath Not facing any issue as such but curious to see how you will handle it.

    • @RahulNath
      @RahulNath  2 года назад +1

      @@MrSachintelalwar Have it in my list, yet to get to it 😀

  • @hozaifamohammed4894
    @hozaifamohammed4894 2 года назад

    Thank you bro

    • @RahulNath
      @RahulNath  2 года назад

      Glad it helped. Do check out the full series here bit.ly/asp-net-core-series

  • @subikshapadmanabhan5842
    @subikshapadmanabhan5842 Год назад

    Hi! I want to save excel files into the local server once every year using scheduler so may i know how to call the excel generating api from my existing controller in my scheduler class

  • @JitheshChandrasekharan
    @JitheshChandrasekharan 2 года назад +1

    Its a hosted service in WebApp, so if I host that web app in Azure? How will the background task behave? So we duplicate background tasks when we scale web app? So background task should manage some locks to avoid duplication? Any thoughts?

    • @RahulNath
      @RahulNath  2 года назад

      Sorry for delay in getting back. Yes as you scale there will be multiple instances. What problem are you trying to solve using background tasks? Using Azure Functions might be another way if you want to control the number of instances and always want only one instance.

  • @deporesmartino1472
    @deporesmartino1472 2 года назад

    hi Rahul, If I deploy service as window service, and some one stop service on service window when it running, how we get the information of stop time

  • @BlalKhalidTech
    @BlalKhalidTech 6 месяцев назад +1

    Hello,What if we want run background service even the application is close?

    • @RahulNath
      @RahulNath  5 месяцев назад +1

      the background job should be running as long as your web app is up and running. Otherwise I would be looking at Azure Function instead of using a Background Task. Does that help?

  • @josephrozario6237
    @josephrozario6237 2 года назад +1

    Nice Tutorial! I want to build a api that start and stop the background task .how can I do that ?if so,than is it the wise way to start and stop the background task?

    • @RahulNath
      @RahulNath  2 года назад

      You could - Can you provide more details on the use case ?

  • @ershadnozari
    @ershadnozari 3 года назад +1

    Hi Rahul, thanks for a another brilliant video. I’m looking for a azure devops ci/cd example for the new Logic Apps Standard. Do you know of a good resource for this? Not looking for entire IaC, rather just continuously build and deploy on commit

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you Ershad and happy you like it. Did you find anything interesting on this channel? ruclips.net/user/Azure4Everyone
      I haven't worked with Logic Apps much.

    • @ershadnozari
      @ershadnozari 3 года назад

      @@RahulNath Hi Rahul, the logic app standard sku just recently went GA with MS Build. Previous devops story for logic app
      was different. The new logic app standard is running on the azure functions runtime, so it is very similar to app services in terms of ci/cd. But I can’t find a good example as it’s so new.

  • @andrewreiser3584
    @andrewreiser3584 2 года назад +1

    Serious question. Someone told me that these tasks are utterly unreliable in Azure. Do you have any experience using them in App Services in Azure? Cheers

    • @RahulNath
      @RahulNath  2 года назад

      Yes I've used this in production in Azure App Service and have had no issues. Depends a lot on how they have used/what error handling mechanisms they have in place. Another option for you would be to make it a web job. What is your scenario?

  • @Ibrahimnada1995
    @Ibrahimnada1995 2 года назад

    good job man

    • @RahulNath
      @RahulNath  2 года назад

      Glad it helped Ibrahim. Do check out the full series here bit.ly/asp-net-core-series

  • @shirazeditar5006
    @shirazeditar5006 Год назад

    👍

  • @santanderhernandezcontador2875
    @santanderhernandezcontador2875 9 месяцев назад +1

    How do you deploy in IIS?
    do you have an example?

    • @RahulNath
      @RahulNath  9 месяцев назад

      I don't have an example for IIS - there are a few on my channel to deploy to Azure Web App bit.ly/azure-devops-series

  • @mdaslamknl
    @mdaslamknl Год назад

    Good
    Why don't you give real life scenerio
    Thanks

  • @habbabbutt3447
    @habbabbutt3447 2 года назад +1

    I want my background service to be run every day at 9AM and run after every 40 minutes till 2PM can you please guide

    • @RahulNath
      @RahulNath  2 года назад

      Suggest looking at WebJobs and using CRON trigger. You could also do this in Background Tasks. Check out libraries like Quartz.net. Hope it helps

  • @rohandeshpande5850
    @rohandeshpande5850 3 года назад +1

    could you please make videos on Razor pages and Core Blazor

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you Rohan for the suggestion. I have added this to my list. But that will not be coming out immediately. Mostly because I have not explored much of Blazor 😀

  • @vadivelk7666
    @vadivelk7666 Год назад

    I want to run my background task for every 30 seconds throughout the year. For this scenario, can I use this approach? Please advice.

    • @RahulNath
      @RahulNath  Год назад

      Sure you can - but if the app is down it won't run, so keep that in mind. Might look at Azure Function on a Timer trigger as well depending on the task and how important it is etc.

  • @iniudoh5941
    @iniudoh5941 2 года назад

    Hi Rahul, great content! I have a bit of an usage when I fake the scope. It's affecting the IHttpContextAccessor, making it return null. can you help?

    • @RahulNath
      @RahulNath  2 года назад

      Thank you - Do you have a example project that you can send me? hello@rahulpnath.com

  • @shashankpandey1019
    @shashankpandey1019 Год назад

    Very nice tutorial ☺️ just i have a question that can we run hosted service as per own events. e.g - when task A is completed then we need to fire background service to execute Task B ?

    • @RahulNath
      @RahulNath  Год назад

      Yes you can use Channels library for this learn.microsoft.com/en-us/dotnet/core/extensions/channels
      But depends what kind of tasks and be aware it will be in memory. If you provide more context on the problem I could give some suggestions.

    • @shashankpandey1019
      @shashankpandey1019 Год назад +1

      Thank You for reply!!
      I have to read an excel having 20k rows and after reading this, we need to execute some business logic for each row.
      1. upload an Excel
      2. Reading Rows and storing in DB.
      3. click on the start process button.
      4. Now we will read all the data from the table and perform some tasks (Business logic) in the background for each row (Total around 20k rows).
      5. Tech Using .Net Core 3.1

    • @RahulNath
      @RahulNath  Год назад +1

      @@shashankpandey1019 I would use messaging for this - so publish a message for each row and process it independently. You can also use background tasks. Once you save the excel records to database signal the background worker using Channels or you can use polling from background job for new jobs/rows in the database. A Message Queue is ideal for these scenarios instead.

    • @shashankpandey1019
      @shashankpandey1019 Год назад

      Thanks a Lot @RahulNath 😊! It's working for me. I have looked at all your videos. it's an amazing learning. Happy leaning!

  • @oggyoggy3033
    @oggyoggy3033 Год назад

    #RahulNath, Hi Sir I have developed this task and its running on my machine,But when i publish on IIS Server its showing Swagger page and jobs are not storing and sending into database,I have watched so many solution nothing is working.Please can you help.Lot of setting i have trying.

  • @hector9079
    @hector9079 3 года назад

    Muy bueno

  • @tulsicreation2026
    @tulsicreation2026 7 месяцев назад

    its wrk in resolving circular reference issue.

    • @RahulNath
      @RahulNath  7 месяцев назад

      Sorry didn't understand?

    • @tulsicreation2026
      @tulsicreation2026 7 месяцев назад

      @@RahulNath want to say i had implemented your solution to resolv circular reference issue in my project , its resolve it.

    • @RahulNath
      @RahulNath  7 месяцев назад

      Great ok - glad it helped!

  • @albertocuevas7353
    @albertocuevas7353 Год назад

    What if I wanted to repeat a task at the beginning of each month

    • @RahulNath
      @RahulNath  Год назад

      You could write some custom scheduling but I would choose Web Jobs/Azure Function with a cron trigger. Is that something that works for you?

  • @shwetagopi5102
    @shwetagopi5102 2 года назад

    Where we have register Ihostedservice if in background task create a zip file. Right now we are register it in last of Configureservice

    • @RahulNath
      @RahulNath  2 года назад

      Sorry didn't understand your question. Can you provide more details Shweta?

    • @shwetagopi5102
      @shwetagopi5102 2 года назад

      @@RahulNath is there any order to add Ihostservice in DI container. My backgroud task is converting body to zip file

    • @RahulNath
      @RahulNath  2 года назад

      @@shwetagopi5102 What problem are you facing with the ordering? It shouldn't be a problem with starting the service

  • @RajendraKumar-zl2kx
    @RajendraKumar-zl2kx Год назад

    How to add multiple cron events inside a single background Service?

    • @RahulNath
      @RahulNath  Год назад +1

      Best to use some external packages for that - Have a look at Quartz.net www.quartz-scheduler.net/
      Hangfire etc www.hangfire.io/
      Or if you can pull them out into serverless functions (Azure Functions, Lambda etc) if you are on cloud. Let me know if that helps.

    • @RajendraKumar-zl2kx
      @RajendraKumar-zl2kx Год назад

      @@RahulNath Thanks for the suggestion. I will try & let you know.

  • @segwitchannel2042
    @segwitchannel2042 Год назад

    will that affect the performance of the web api.

    • @RahulNath
      @RahulNath  Год назад

      Depends on where you are hosting and what you are doing in the Background Tasks. If it's resource heavy you can decouple it to a Function/Lambda (depending on what your hosting platform is).

  • @sarathbaiju6040
    @sarathbaiju6040 2 года назад

    Is any way to stop the backgroundjob task other than application shutdown? i am eargly waiting for your response

    • @RahulNath
      @RahulNath  2 года назад

      Sorry for the delay. Yes you can exit the loop and run only once or based on your conditions. the first job I show in the example closes down after first execution. If you can give more details on your use case I could suggest something.

    • @sarathbaiju6040
      @sarathbaiju6040 2 года назад

      @@RahulNath my use case is i created a background service to subscribe a kafka topic. As you said the while loop in the background service exist only when application goes to shutdown. My requirement is to create an endpoint or something that control the start and stop of background task. I don't know it is possible. If its possible please reply.

  • @roslanbainal5914
    @roslanbainal5914 3 года назад

    this method can be used for sending
    email automatically for specific user which is inactive user more than 6 month?

    • @RahulNath
      @RahulNath  3 года назад +1

      Yes you could, but if you are on Azure I might use a Web Job or an Azure Function for that. But that said, you could very well do that in BackgroundTask as well

    • @roslanbainal5914
      @roslanbainal5914 3 года назад +1

      @@RahulNath thank you sir for your explanation 👍

    • @RahulNath
      @RahulNath  3 года назад +1

      @@roslanbainal5914 No probs Roslan. And you can call me Rahul 😀

  • @miguelangeltaipemamani4840
    @miguelangeltaipemamani4840 2 года назад

    In webforms?

    • @RahulNath
      @RahulNath  2 года назад

      haven't tried yet. Did you get a chance to explore?

  • @developeratvcsvietnam150
    @developeratvcsvietnam150 2 года назад

    this is .net core 3.1 ? how to create in .net 6 bro?

    • @RahulNath
      @RahulNath  2 года назад

      Guessing most of it will be the same - What difficulties are you facing?

  • @Kasiux
    @Kasiux 2 года назад

    Every time I start my web API , the worker doesn't start with it... Of course I added it in program.cs

    • @RahulNath
      @RahulNath  2 года назад

      Hard to tell what might be the reason. Did you try adding a log statement in your background task startup?

    • @Kasiux
      @Kasiux 2 года назад

      @@RahulNath I added logs, breakpoints, database queries. It just won't be executed. The process is running under IIS express (rest API)

    • @Kasiux
      @Kasiux 2 года назад +1

      @@RahulNath okay, smh it's working now. But not instantly when I start the process but only after I did a first request to the backend over the frontend?! So if I just start my API, the worker won't instantly start. As I log in from the frontend a request will be sent to the API (just casual stuff) and then the worker starts. (After a request)

    • @RahulNath
      @RahulNath  2 года назад

      @@Kasiux Think it should work as soon as app launches. Can you create a minimal sample and send it to me and I can check - Details in the about page.

  • @user-dd3qx2pr8l
    @user-dd3qx2pr8l Год назад

    0:36

  • @madd5
    @madd5 3 года назад

    Can you try to mimic English or US accent? That way it would be less frustrating to listen to your videos and more people would join LOL

    • @RahulNath
      @RahulNath  3 года назад +1

      Haha, never thought that would be a reason for people not joining. Also can't tell if the people who have joined are because I don't have one. 😀

  • @fahadnoor2579
    @fahadnoor2579 3 года назад +1

    Excellent

    • @RahulNath
      @RahulNath  3 года назад +1

      Thank you so much Fahad😀 Make sure to check out the other videos in this series ruclips.net/p/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP