This guy deserves more subscribes and more views. He is providing very great, useful and easy to understand content . Keep up the good work Tim and thank you very much for sharing your knowledge.
@IAmTimCorey5 жыл бұрын
I appreciate the kind words.
@acveigascs4 жыл бұрын
I totally agree. Great content :)
@allenbythesea3 жыл бұрын
he needs to learn to summit mount point faster though. His videos has so much filler it takes forever to get to the point.
@jeremyrooks97843 жыл бұрын
I’ve learned more from Tim in 6 months than I did in 6 years of college…
@PeterMisovicProfile3 жыл бұрын
Great channel!
@clintaionasmith3 жыл бұрын
FYI - Deleting the service and files is not necessary to update the executable. You can just stop the service, publish your changes, and then start the service up again. Aside from that this is an EXCELLENT tutorial!
@IAmTimCorey3 жыл бұрын
True, but by deleting the files, you ensure you don't leave any scraps behind from the old application. It is a good practice to have.
@clintaionasmith3 жыл бұрын
@@IAmTimCorey That is a valid point although perhaps only really necessary once you're ready to deploy to production. During development and testing it seems a bit excessive, and I've had cases where deleting a service failed and the only resolution was to reboot. I guess I'm just a bit more gun shy about creating/deleting services more than absolutely necessary.
@CodeZombie622 жыл бұрын
Tim, I've recently started work on a Windows Service project and I've been looking all over for examples on how to do it. By far, this has been the clearest example that I've seen. Thanks, Scott
@IAmTimCorey2 жыл бұрын
I am glad it was so helpful.
@CoderboyPB3 жыл бұрын
Tim, if we wouldn't have Covid currently, I would kiss you: At Minute 8:00 you made clear to me, what several (text) tutorials about this topic missed before: It's an endless process and it restarts every second. You are a wonderful tutor !!!
@IAmTimCorey3 жыл бұрын
Glad I could help!
@birdasaurusrex2 жыл бұрын
THANK YOU! I watched your other video on services ~1 year ago and thought "that's interesting, but I don't think I'll use that"...At work I was just asked to write a simple monitoring tool for our other services and this came in immensely handy.
@IAmTimCorey2 жыл бұрын
I am glad it was so helpful.
@tickprophet4 жыл бұрын
Great video. Of note, if you are simply updating the service, you can stop the service, copy/replace the files and start the service. No need to uninstall.
@IAmTimCorey4 жыл бұрын
True, but uninstalling makes sure you remove all of the files.
@konoko-o3o2 жыл бұрын
Absolutely amazing video, I started my internship as C# developer today, the project that I'm working with have a lot of worker services this video is very useful.
@IAmTimCorey2 жыл бұрын
Fantastic!
@ateeqrahman53962 жыл бұрын
The concepts are explained very clearly and in detail. The demo is simple yet powerful enough to grab the full concept.
@IAmTimCorey2 жыл бұрын
Thanks!
@fidel_soto3 жыл бұрын
Previously we had to use Topshelf and code a lot for logging into a file. I'm glad to see its all getting standardized. Great topic, great teaching, great video.
@IAmTimCorey3 жыл бұрын
Glad it was helpful!
3 жыл бұрын
I love the clarity with which you expose. I will use this new knowledge to create a database backup tool that replicates Mega and Dropbox backup. I have multiple clients using SQL Server Express and I need to maintain a good backup policy on each one. Thank you very much for the great content
@IAmTimCorey3 жыл бұрын
Awesome! I am glad to have helped.
@sk00pidis Жыл бұрын
Amazing work! I was asked during training at my job to create a windows service and this one covered everything in great detail! Thank you mr.Corey
@IAmTimCorey Жыл бұрын
You are welcome.
@tahmideshayat18495 жыл бұрын
love your tutorials man. helping a lot in my job. love from Sydney
@IAmTimCorey5 жыл бұрын
Awesome!
@luiscreates3 жыл бұрын
Watching this to upgrade a .NET Framework 4.5 windows service to .NET5. Great video!
@IAmTimCorey3 жыл бұрын
Glad it helped!
@smiley24742 жыл бұрын
i am new to c# and it's quite challenging for me. but i have discovered your channel and will study your material slowly by slowly. hopping to learn a lot
@IAmTimCorey2 жыл бұрын
Great!
@adventureschannel96442 жыл бұрын
Excellent tutorial. Clear and easy to follow. Thanks a bunch Tim.
@IAmTimCorey2 жыл бұрын
You are welcome.
@ricardomlourenco Жыл бұрын
Absolutely great content. I loved how you start to really a beginner then you gradually progress to a more complete solution, adding log and configuring Windows Service. Loved it. Thank you so much for the great content.
@IAmTimCorey Жыл бұрын
You are welcome.
@zoltan.halasz4 жыл бұрын
I wanted to try background jobs in windows, and exactly that is covered here. Great material, clear and concise until the end!
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@sergZh785 жыл бұрын
Im study english only for you videos It is a lot of information
@IAmTimCorey5 жыл бұрын
Great!
@francomorales42945 жыл бұрын
Hi man, excellent tutorial and great & clear explanation! I'm evaluating create a windows service to check some tables in the db and I'll try to do that with net core 3.0 ! Thank you for sharing your knowledge! Cheers from Argentina!
@IAmTimCorey5 жыл бұрын
Thank you!
@AmitSharma-bl1ur5 жыл бұрын
Sir Your voice is marvelous , Every Student pray to get Teacher Like You, Sir I want to learn Xamarin but did not find any good tutorial about this can you provide some tutorial about Xamarin to get Started
@IAmTimCorey5 жыл бұрын
I am going to be covering Xamarin in a couple months.
@AmitSharma-bl1ur5 жыл бұрын
@@IAmTimCorey Thanks Sir for quick reply
@AllenMichaelsVlogs5 жыл бұрын
Absolutely fantastic! I wish there is a second part to this on how to add the installer.
@IAmTimCorey5 жыл бұрын
What do you mean "add the installer"? You can run the command I showed on screen for installing the service on any machine. What are you looking for beyond that?
@AllenMichaelsVlogs5 жыл бұрын
@@IAmTimCorey in my situation I would have a system admin do the installation and they want to use the installer and not the command tool
@AlexKidd4Fun4 жыл бұрын
@@AllenMichaelsVlogs In the past, I was able to generate an MSI (Microsoft Installer) that would deploy the bits and set up services using Flexera Installshield. It might not work for the project type demonstrated here as their website doesn't list support for .net Core 3 yet but I suppose it's only a matter of time. Give that a look - it was very simple to set up the package once compiled.
@88spaces2 жыл бұрын
Thank you, Tim. This is a very informative video. I watched it because I have a service that needs to run but I'm choosing to run it as a console app under the Windows Task Scheduler. I still wanted to explore my options though.
@IAmTimCorey2 жыл бұрын
You are welcome.
@camcommute2 жыл бұрын
I used to use the console app as a Windows task scheduler but I've noticed that it pop up the command prompt everytime it run. Have u found a way to disable this?
@shvideo15 жыл бұрын
Great topic and tutorial. Very useful information. Thank you also for covering the uninstall service.
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@adedotunrichard86912 жыл бұрын
Thank you for this great work. I will like to try the worker service to run some certain background services for my application. Thank you once again
@IAmTimCorey2 жыл бұрын
You are welcome.
@alinpaul42683 жыл бұрын
great video Tim, also great content on your website. Keep up the good work. I hope people can make the difference between quality content like yours and other "made on the knees" content who just floods youtube and other chanels.
@IAmTimCorey3 жыл бұрын
I am glad you are enjoying my content.
@marcospalladino19633 жыл бұрын
Tim, it was very nice. Thank you. Please, send more videos about Worker Services, but now, working the advanced ways. Example: "Worker Services with Selenium automation"
@IAmTimCorey3 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@marcoscarvalho99563 жыл бұрын
Thanks Tim you helped me a lot with your detailed explanation. Translation by Google.
@IAmTimCorey3 жыл бұрын
You are welcome.
@norryowlmalahan51362 жыл бұрын
A bit old thread here but the first time when I met worker service was trying to make Hangfire running in a Docker container :)
@fastbowler384 жыл бұрын
Excellent video ! You should have a "buy me a coffee" button.. I would have gladly bought you a couple ! Great Work again !!!
@IAmTimCorey4 жыл бұрын
You could go to www.patreon.com/IAmTimCorey and buy me one there
@lukassrovnal93122 жыл бұрын
Many thanks for this video, finally i get it how it all works!
@IAmTimCorey2 жыл бұрын
Awesome!
@jonannin2 жыл бұрын
Excellent delivery. Thank you.
@IAmTimCorey2 жыл бұрын
You are welcome.
@facundopugliese96323 жыл бұрын
This is one of my favourite videos. I really enjoyed it. Thanks, Tim. I'm going to automate everything.
@IAmTimCorey3 жыл бұрын
Glad you enjoyed it!
@whirlwnd14 жыл бұрын
Very useful, Very to the point, Well explained, Solid... Thanks Tim
@IAmTimCorey4 жыл бұрын
You are welcome.
@Navelpluisje4 жыл бұрын
Hi Tim, that was excellent thanks for the lesson. I am monitoring all websites on the web now.
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@ManiasInc4 жыл бұрын
Thank you very much Tim! for all the knowledge you provide, your effort and time you invest to teach. Thank you very much!
@IAmTimCorey4 жыл бұрын
My pleasure!
@thingstodowithBASS4 жыл бұрын
Very very good! Beautifully articulated the context of use. You deserve far more views then you have!!
@IAmTimCorey4 жыл бұрын
Thank you.
@frederickmanlusoc20503 жыл бұрын
A very understandable explanation. Great job sir!
@IAmTimCorey3 жыл бұрын
Glad it was helpful!
@BobDenny5 жыл бұрын
Who knew? It just happens I am converting a console app / service that I wrote years ago from .NET Framework to .NET Core. I did the service bare metal using InstallUtil. That's fine, but It appears that this will accomplish the same thing in COre, and give me a Linux Daemon on top of it, with much simpler code. I am just lucky to have stumbled across this !!
@IAmTimCorey5 жыл бұрын
I'm glad you found it. Yep, this should do all you want in a packaging that is easier to manage.
@VictorPraizTech Жыл бұрын
Thank you Tim 🎉
@IAmTimCorey Жыл бұрын
You are welcome.
@cavalsilva2 жыл бұрын
Hello Tim, thanks for the video, is very useful!
@IAmTimCorey2 жыл бұрын
You are welcome.
@jovicamilenovic28995 жыл бұрын
When using classic WindowsServices for example, you just have to stop the service, recompile the service project with your changes and start the service again. You don't need to delete the deployment files or the delete the service. Just restart the service after recompile. Can we still use OnStop OnShutdown OnPowerEvent from ServiceBase? Very nice intro to Worker Services!
@IAmTimCorey5 жыл бұрын
Yeah, I just prefer to clean it out and start over. Otherwise, you might end up with artifacts from a previous installation. And yes, I believe we do.
@alvinbernardo95514 жыл бұрын
another clear and help full tutorial
@IAmTimCorey4 жыл бұрын
Glad it helped
@CarlosHerreraJugovie3 жыл бұрын
Excellent video dude, thanks so much...!!! - Greetings from Caracas / Venezuela
@IAmTimCorey3 жыл бұрын
You are welcome.
@fzamick2 жыл бұрын
just wow thanks again Tim!
@IAmTimCorey2 жыл бұрын
You are welcome.
@alexy.35125 жыл бұрын
Brilliant. I have been evaluating whether .Net Core is a good fit for mixed Windows/Linux environment, which requires small microservices like this (not this simple). And you basically answered it. Thank you! Awesome stuff.
@IAmTimCorey5 жыл бұрын
Awesome!
@lakshminarayanans9252 Жыл бұрын
Amazing Tutorial Tim!!
@IAmTimCorey Жыл бұрын
Thanks!
@tamerezzeldin44043 жыл бұрын
Great video & simply explained! Thanks!
@IAmTimCorey3 жыл бұрын
You're welcome!
@samerelsahih2 жыл бұрын
Great content as usual I can't skip a single video from your channel ! Do you think it would be a good idea or even possible to create a worker that can update a memory cache in the background when database changes occur ? Is such a concept possible with this ?
@novedadesdanny28293 жыл бұрын
Excellent your tutorial. I think that is better than hangfire.
@IAmTimCorey3 жыл бұрын
You can actually use hangfire inside of a service. Hangfire is more about scheduling where services are about running something continually in the background.
@ChosenHandle3 жыл бұрын
This was excellent content. Succinct and informative. Thank you tim!
@tomthelestaff-iamtimcorey75973 жыл бұрын
Thanks for sharing
@Coeur855 жыл бұрын
Awesome tim , amazing as always, hope to see one grpc service :)
@IAmTimCorey5 жыл бұрын
Thank you! People have been requesting gRPC so I'll keep bumping it up the priority list.
@venky76v5 жыл бұрын
@@IAmTimCorey gRPC as well as GraphQL might interesting. Tim you are briiliant. I am coming off your Docker course and I must say it has been one of the courses that I have had. Keep it going.
@fatihduzenli58935 жыл бұрын
Thanks for all your videos and efforts on teaching C# with a great detail. Could you please also make a video about good books to read for C#? I would like to know what books you would recommend worth reading. Thanks in advance.
@IAmTimCorey5 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@dsmyify5 жыл бұрын
CLR via C# is a good book.
@fatihduzenli58935 жыл бұрын
@@dsmyify did you read that book ? Is it like from beginner to advance, covering all topics in depth with good examples ? Because I heard that book when i was searching on google. In addition, i have seen "c# 7.0 in a nutshell: the definitive reference" multiple times. I m not sure cause I want to buy a book that is comprehensive and nearly up to date.
@dsmyify5 жыл бұрын
@@fatihduzenli5893 ~ it's an advanced book. It's about the CLR and how C# works under the covers. It's learning the underlying concepts of .NET. It is a good book. Makes you think about memory allocation and using the right types structures or classes, it takes about the difference between instance and type methods, and things like that.
@dsmyify5 жыл бұрын
@@fatihduzenli5893 ~ it might be worth seeing if a similar book for Core comes out.
@RalfsBalodis3 жыл бұрын
0:00 - Intro 1:15 - Creating Demo Worker Service App 2:54 - What is a Worker Service 3:59 - Service App template code overview 9:32 - Service App code design using http client 20:15 - Showing log messages: Serilog NuGet references 22:22 - Showing log messages: Serilog configuration 25:00 - Showing log messages: Implementing Serilog 29:45 - Configuring Worker Service for Windows: WindowsServices NuGet 31:32 - Deploying the Service App 33:39 - Installing the Service using PowerShell 37:26 - Uninstalling the Service using PowerShell 39:24 - Updating, deploying, installing and uninstalling the Service 44:04 - Summary and concluding remarks
@IAmTimCorey3 жыл бұрын
Thanks again!
@leefig60894 жыл бұрын
This is fabulous. Thank you Tim
@IAmTimCorey4 жыл бұрын
You are welcome.
@viniciusamaraal4 жыл бұрын
Very good explanation!
@IAmTimCorey4 жыл бұрын
Thanks!
@RawCoding5 жыл бұрын
A little bit slow pace for my liking but you are covering a lot of ground here nice work Tim! This way is a lot nicer than the current 2.* way.
@IAmTimCorey5 жыл бұрын
Thank you!
@TheDumpap5 жыл бұрын
Really appreciate the work you are putting into your content! :)
@IAmTimCorey5 жыл бұрын
Thank you!
@robertotomas4 жыл бұрын
tip: skip to 3:00, this is the context you need to know what you are looking at, then go back and watch how he creates it if you don't already know where it is in the new project menu
@IAmTimCorey4 жыл бұрын
I'm glad you find it valuable enough to come back to.
@hattinnh4 жыл бұрын
I really wish you all the best! Your videos have been very helpful! Thank you for sharing your knowledge!
@IAmTimCorey4 жыл бұрын
You're very welcome!
@superkoyo4 жыл бұрын
Nice video! thx from Brazil.
@IAmTimCorey4 жыл бұрын
Thanks for watching!
@shaktisingh-lu3dm3 жыл бұрын
Thanks a lot Tim. Really enjoyed learning this new concept for me. :)
@CarlosPerez-te4gx4 жыл бұрын
Great job Tim. Thanks a lot, great presentation.
@IAmTimCorey4 жыл бұрын
Thank you!
@marcusreinicke4 жыл бұрын
Thanks very much Tim for your great work. You are the best
@IAmTimCorey4 жыл бұрын
Thank you!
@Umer1715 жыл бұрын
Excellent lecture deserve respect... Like
@IAmTimCorey5 жыл бұрын
Thank you!
@UnknownMoses12 күн бұрын
For debugging and testing Windows Services I would always put the code in a class library and create a Windows application that references that class library. I then write the code in the class library debugging and testing it from the Windows application. After I am think I am about done, I added a Windows Service project and referenced that same class library and executed by calling the same methods from the Windows Service. I would add a timer delay or task delay in the service of say 20 seconds. Then I would install the service and run it, the delay is so I could attach the visual studio debugger to the running service. This way I could step through all the code and test it all that.
@IAmTimCorey11 күн бұрын
The good news is that you don't need to do all of this work now with worker services.
@UnknownMoses4 күн бұрын
@@IAmTimCorey The only thing that sort of irritates me about the newer frameworks over Net Framework 4.8 is the lifecycle. I it feels like every couple years I have to update applications to a newer version of NET where as with Net Framework 4.x I did not have to update projects to newer versions of the framework. I would like NET to stop releasing new versions and just update the major and minor builds like they did with the old Net Framework.
@mehr525 жыл бұрын
Thank you Tim, it was awesome!
@IAmTimCorey5 жыл бұрын
You are welcome.
@alexanderspiegel67475 жыл бұрын
Thanks Tim for one more nice lesson.
@IAmTimCorey5 жыл бұрын
You are welcome.
@alexanderspiegel67475 жыл бұрын
Tim, what can be the best way to ask some questions? If it is possible of course.... here ? Or via email?
@dileepkumarpd4 жыл бұрын
It's Really nice man..! And very clear explanation.!
@IAmTimCorey4 жыл бұрын
Glad you liked it!
@maqsudbeknurmatov39982 жыл бұрын
good job and good luck bro!!!
@pravingade60534 жыл бұрын
Nice video...Thanks for explain very detailed
@IAmTimCorey4 жыл бұрын
Most welcome 😊
@fikerehman96145 жыл бұрын
Very useful. Please keep up the good work. Only thing I noticed that you could use string interpolation to make code more readable. instead of saying Log.info("Web Site Status: {statusCode}", statusCode); could do : Log.info($"Website Status: {statusCode} "); notice the '$'
@IAmTimCorey5 жыл бұрын
Actually, there is a difference. I pointed it out briefly. If you do it my way, a structured logger like Serilog can pull out that data and store it separately so that you can query on it later in the logs (where statusCode = 401 or temperature > 50 would be examples). If you use string interpolation, you only get a string stored in your log statement so you would need to do a regex match to try to pull out the values.
@brentzeiss23873 жыл бұрын
Thanks for your video. It's so in depth. Are you able to do a video on automating the deployment of a windows service? Eg Deploying from some generic CI/CD pipeline on some server and deploying the service to another server that may or may not have the service already running?
@tomthelestaff-iamtimcorey75973 жыл бұрын
I added it to Tim's list for topics to consider. Thanks for recommending it.
@MsYogeshPandey2 жыл бұрын
Very useful video, Thank u Tim 💯😊
@MsYogeshPandey2 жыл бұрын
Is worker service useful for scheduling a task on daily basis?
@IAmTimCorey2 жыл бұрын
Thanks. And yes, they can be useful for scheduling daily tasks.
@MsYogeshPandey2 жыл бұрын
@@IAmTimCorey Wow! so quick response.. I really not expected this fast. Hats off to you Tim, our devs community must be loving you a lot. Love from India too 😘
@kangooroovd2 жыл бұрын
thank you for making this video
@IAmTimCorey2 жыл бұрын
You are welcome.
Жыл бұрын
Hi Tim, I'm a hugh fan of your videos. Microservices are very popular nowadays. Could you make a video about dapr? I use it for a while and it would be very helpful for your followes too.
@IAmTimCorey Жыл бұрын
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@edrianjerusalem12584 жыл бұрын
finally! a way to debug a window service :D
@IAmTimCorey4 жыл бұрын
I hope it helps
@MaximilianGe3 жыл бұрын
Logging (Windows Event Log) is working only on my windows 10 PC, did not work on Windows Server 2016. Any Idea?
@tkytessy3 жыл бұрын
Hey...I just went through this demo and created the same...ur demo was very helpful...Is there any way to call an already existing api in the worker service... Thanks in advance
@PiterMorbid3 жыл бұрын
Great video! Completely understood. The outstanding question I've got, though, is how or where do I pass a Cancellation token to end my service operation?
@MohdMoinuddinVohra5 жыл бұрын
Nice explanation. Thank you so much for sharing.
@IAmTimCorey5 жыл бұрын
You are welcome.
@alexismyname34213 жыл бұрын
Is there a way to automatically install and start the service aswell? Nice vid btw very helpful! I want to use the worker to automatically add and commit the changes in svn, do you think this is a good practice?
@robertosterberg2 жыл бұрын
Hi Tim great video you mention the possibility to trigger the service based on an event in a database could you elaborate on that. Is that done on the DB side using events or sound really interesting. Love you r videos i get so much inspiration from this keep it up!
@IAmTimCorey2 жыл бұрын
A worker service can monitor the database for changes by just calling a small query on a schedule. If something has changed, it can get the new data and do something. For example, if you had a People table, you could do a "select max(id) from People", which would return the last identifier issued. Let's say the first time it is called, you get back id number 10. If you run it again and you get back id number 12, you know that you have at least one new record. You can run "select * from People where id > 10" to get the new records.
@luisantonioparamoromero95123 жыл бұрын
Thank You for the video, it really helped me out, i have a question, is there a way to make an installer like we do un ServiceBase? I need it for a setup proyect
@mohammadusman16885 жыл бұрын
Thanks for this detailed video. Really helpful.
@IAmTimCorey5 жыл бұрын
You are welcome.
@chrisogonas5 жыл бұрын
Well delivered, and many thanks!
@IAmTimCorey5 жыл бұрын
You are welcome.
@dernordischegott1233 жыл бұрын
Thanks for your Video - like the others awesome!
@tomthelestaff-iamtimcorey75973 жыл бұрын
Thanks for sharing!
@Gonkers445 жыл бұрын
Looks like a great video for beginners.
@IAmTimCorey5 жыл бұрын
Thanks!
@irfanakunkerja71793 жыл бұрын
Thank you. Awesome tutorial. I wonder how to create a unit test for a worker service. Do you have any references for that? Thanks in advance
@tomthelestaff-iamtimcorey75973 жыл бұрын
Topic suggestion noted and have added to Tim's list of viewer requests, thanks.
@maxron65142 жыл бұрын
@@tomthelestaff-iamtimcorey7597 i am heavily interested. did you do that already?
@tomthelestaff-iamtimcorey75972 жыл бұрын
@@maxron6514 Not yet. I would love for you to post this video recommendation on Tim's Suggestion App - suggestions.iamtimcorey.com/. Tim just implemented a new feature so that you will get an email if/when Tim completes the recommendation.
@rolandomedina71404 жыл бұрын
Great tutorial man! Thanks a lot from Panamá!
@IAmTimCorey4 жыл бұрын
You are welcome.
@owenlagula58123 жыл бұрын
Love it. Thanks!
@IAmTimCorey3 жыл бұрын
You are welcome.
@pyrejke29915 жыл бұрын
Thanks Tim. It's really simple and usefull staff to start. It would be nice if you record new video with more cool things and deploy it to Azure.
@IAmTimCorey5 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@RafCalg3 жыл бұрын
That was good and valuable.
@IAmTimCorey3 жыл бұрын
Great!
@b33hzad4 жыл бұрын
Fantastic video. thanks a lot.
@IAmTimCorey4 жыл бұрын
You are welcome.
@zachb80125 жыл бұрын
Wow these services are easy, I wish I didn't make like the exact same thing as your sample project with a standalone Azure Timer Function.
@IAmTimCorey5 жыл бұрын
Yep, they are really easy.
@TheChandraak2 жыл бұрын
Thank you for valuable lesson. Could you please tell how to containerize this worker service. ?
@IAmTimCorey2 жыл бұрын
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@str0g3 жыл бұрын
in ur example you used the worker service for monitoring a website. But how do you do that when you want to watch a directory with file system watcher?
@ManojThakur-ig4mk4 жыл бұрын
Great video..love it.. is it better to do the scheduled task using time check in WorkerService or I would prefer some other library for scheduling tasks??
@IAmTimCorey4 жыл бұрын
You can do either. The best solution for scheduled tasks is probably HangFire though.
@ManojThakur-ig4mk4 жыл бұрын
@@IAmTimCorey Thank you very much for response
@Coldshoulders694 жыл бұрын
Great content! You've gained a new follower
@IAmTimCorey4 жыл бұрын
Excellent!
@JoeBonez5 жыл бұрын
Great video! Subscribed. The only thing that raised my hackles, is that I would have done client?.Dispose() out of an abundance of caution.
@IAmTimCorey5 жыл бұрын
That wouldn't hurt and there is a small possibility it could help. Good catch.
@immersivegamer4925 жыл бұрын
My thought was that you could also do a using statement wrapped around the while loop (just for this simple case, other cases cleaning up in stop method is correct)
@mihaimyh5 жыл бұрын
I have another question, if that's ok: how can we unit test this since it has a hard dependency on BackgroundService class and also the methods are protected. Or we don't?
@IAmTimCorey5 жыл бұрын
In order to test this well, you would want to move your logic out of the ExecuteAsync method and into a class that you can test more easily.
@Antmanzzz4 жыл бұрын
Tim might know better, but AFAIK there's no good way to write true unit tests for static methods or classes with hard dependencies or restricted method signatures. However you can work around it to some extent by minimising the amount of your code residing in those places. In this case you could create a new public class WorkerHelper with the same _logger member, constructor and 3 methods as the current Worker class (just copy-paste Worker.cs and rename), but then make the methods public virtual instead. This can then be unit tested. Then modify the original Worker class to forward to _helper as follows: public class Worker { private readonly WorkerHelper _helper; public Worker(ILogger logger) { _helper = new WorkerHelper(logger); // new is OK here since cannot unit test, and no worse than current impl. } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await _helper.ExecuteAsync(stoppingToken); } //etc... } Also when you want to test a protected method in a non-sealed class (and you are unable to make the method protected internal etc) then it is still possible to test this using a hack/trick. Extend the class (e.g. MyClass) in a new class MyClassTestable in the same project as your tests. Add a public method that calls the protected method with the same signature. Voila you can now write tests for that method. Normally you would use this 'Testable' pattern for other reasons, but it does help in these cases too. Finally, you can (and should) also write at least one integration test on any service component like this. That test can often outweigh the value of all the unit tests combined.