Intro to Windows Services in C# - How to create, install, and use a service using Topshelf

Поділитися
Вставка
  • Опубліковано 16 лип 2024
  • Full courses: www.iamtimcorey.com/
    Patreon: / iamtimcorey
    Newsletter signup: signup.iamtimcorey.com/
    Topshelf Link: topshelf.readthedocs.io/en/la...
    Services in Windows are really powerful tools for automation, but they are often overlooked. These small applications run constantly in the background and can be used for a number of tasks from the simple to the complex. In this video, we are going to look at how to create a service, how to run it and debug it, and how to install it.
    0:00 - Intro
    0:51 - Creating Console Demo Application
    1:45 - What is a Windows Service
    3:30 - Visual Studio service app template vs console app
    5:00 - Topshelf NuGet reference
    5:58 - Service app code design
    20:49 - Running the Service App
    22:07 - Installing and uninstalling the Service
    26:44 - Recap
    27:11 - Ideas for a Service Applications
    30:10 - Summary and concluding remarks
    Thanks to Ralfs HBK for the chapter breakdown

КОМЕНТАРІ • 797

  • @Stolen_Bus
    @Stolen_Bus 4 роки тому +6

    I don't know if you'll ever read this, I started learning C# about 2 weeks ago. I needed a new hobby for the quarantine and I figured that this one will do. You're honestly one of the most gifted people in passive knowledge I've ever encountered in my life, thank you for all the work you're putting in for us common people to learn. I can only wish you to never stop doing this for as long as you're enjoying this. Thank you very much.

    • @IAmTimCorey
      @IAmTimCorey  4 роки тому +2

      I am glad my content is so helpful to you. Thank you for the very kind words.

  • @germang.4514
    @germang.4514 3 роки тому +5

    if I had discovered this channel earlier, I would have saved myself a lot of headaches.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +2

      Well, I'm glad you found it eventually.

  • @jonnywilson375
    @jonnywilson375 5 років тому

    What an absolutely SUPERB video - so well explained and I wrote a Windows Service in less than 3 minutes after watching this start to finish. Absolutely brilliant. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are welcome. I'm glad you enjoyed it.

  • @debkelly63
    @debkelly63 5 років тому

    Thanks Tim! This couldn't have come at a better time. I just started to write a service on Friday and now I'm going to do it this way. Love your videos; they are so easy to understand.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Nice! I'm glad you will be able to make use of this right away.

  • @bryandpalmer
    @bryandpalmer 5 років тому

    I made a small service to routinely clean up my downloads folder like you suggested. Works great! You are inspiring me to "play with" C# more than I did in the past with all these great tutorials!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Awesome!

    • @harag9
      @harag9 5 років тому

      Excellent, just be careful with tasks like that, you don't want to be cleaning up your C:\ drive by mistake :)

  • @jianhuichua1154
    @jianhuichua1154 5 років тому +1

    I'm a junior c# full stack developer and I have to say Sir , you are a great help, not only make it easy to understand with step by step tutorial and also with a very clear and easy understand explanation. Thank you.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are most welcome. Thanks for watching.

  • @harag9
    @harag9 5 років тому +1

    Wow, I'd heard about TopShelf, but never really looked into it, this makes debugging services so much easier - and looks easy to convert existing services to use Topshelf - Thanks Tim!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are welcome. I'm glad it was so valuable to you.

  • @marcjacquinot6363
    @marcjacquinot6363 4 роки тому

    Messing around with NSSM utility to run existing applications as a service, I decided to look for way to write my own service from scratch for more flexibility and to come up with a rock-solid approach that also allows easy debugging and testing. Found your "Windows Services in C#" tutorial -> bullseye! Thanks for your great work.

  • @TheJessejunior
    @TheJessejunior 5 років тому

    hey man, i have no words to thank you for some such i´ve learned from your videos this year. they´re always so complete and simple to understand.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      I am glad my content has been so helpful to you.

  • @philgibbings6510
    @philgibbings6510 Рік тому

    cheers for this , i was trying to create a service using the windows service which wasnt pleasent, from this video ive adopted topshelf and its worked a treat. i now have managed to create a service that checks for USB sticks being inserted, and if usb has a serial that matches our data base it will check to see if ir requires a update,and if it does it then updates it accordingly. Great video Tim keep up the good work

  • @a.porteghali7402
    @a.porteghali7402 2 роки тому

    Many Thanks Tim, I used to apply a do-while-loop to let a program keep running. I heard about the services as a best practice in such a circumstances but it looked a little scary to me. Thanks you again for make it so simple and understandable.

  • @rodrigo6459
    @rodrigo6459 5 років тому +1

    Have been waiting for this topic for a REALLY long time!!! thank you a LOT TIM!!! you are taking this channel to the next level... not kidding here!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Awesome! I'm glad you finally got it. You are most welcome.

    • @rodrigo6459
      @rodrigo6459 5 років тому

      Is it possible to have a service that accept parameters when windows starts?...

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Interesting question. What are you thinking about? It would seem like if you could pass parameters in, you could do the same without needing to pass them in (maybe app.config settings) since you wouldn't be getting user interaction.

    • @rodrigo6459
      @rodrigo6459 5 років тому

      Working on a "listener" for a GPS hardware that will transmit information to my server which will store the data in an Azure Cosmo DB, so basically it will be great to pass for example, a specific port to use, max concurrent connections from a certain GPS or even "query" the service for uptime, current connected devices and stuff like that.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому +1

      Yeah, I think updating the app.config or even a local database might be the solution here. As for querying it, you could actually just store that info in a local database (updated in real-time) and then read the database from anywhere you need that info.

  • @dronefootage4115
    @dronefootage4115 2 роки тому +1

    Love the detail and simplicity of this video. Excellent.

  • @rupertopasillas
    @rupertopasillas 5 років тому

    WOW! I've been avoiding using services for over 10 years cause of the messiness of troubleshooting while developing. Today while watching your video, I learned how to, and proceeded to convert a simple console application to a service. Thanks a million!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Awesome! I'm so glad it helped.

    •  5 років тому

      Hi, I've been using services a lot, but they allways come with console sibling. My pattern was very simplistic. Entire job was done in class library and service in start/stop methods only called start/stop methods in class library. The same job is doing console application. Debuging was easy, just debug console application. And for fun, sometimes forget to reference some library in service application :)

  • @user-dh7hq9qt5s
    @user-dh7hq9qt5s 8 місяців тому

    Tim - thanks - I just finished your c# mastercourse (which was great!) and am embarking on my own projects to build a portfolio. I have a desktop scanner and a printer, and I'm going to create a service that watches the folder for newly scanned pdfs and then prints them - essentially a photocopier. Thanks to your helpful videos, I think I can pull this off.

    • @IAmTimCorey
      @IAmTimCorey  8 місяців тому

      Awesome! Great job and great idea.

  • @arthurnamu5770
    @arthurnamu5770 5 років тому

    Tim, Tim... You have been of immense help in my career. And this one is just Exceptional!!!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      I'm glad I've been so helpful.

  • @llopez9967
    @llopez9967 2 роки тому +1

    Thanks Tim, I am so glad that I came across your channel!

  • @lawre_17
    @lawre_17 3 роки тому

    The best lecture ever. I was Wondering on how to sync SQLite database files to the main server and I thought of checking how services work and here you explained it so clearly Thank you

  • @alexstahl1875
    @alexstahl1875 2 роки тому +1

    You are a life saver. This was exactly what I was looking for. Perfectly explained and super easy to follow.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I am glad it was so helpful.

  • @abhijeetkulkarni8261
    @abhijeetkulkarni8261 4 роки тому +1

    Thank you so much tim. This is an amazing video. Excellent explanation.
    I am going to write a service that clears my temp folder periodically so that it doesn't slow my system.

    • @IAmTimCorey
      @IAmTimCorey  4 роки тому

      Great! I’m glad it was helpful.

  • @IsackOliveira
    @IsackOliveira 2 роки тому

    more than 15 years since my last visual basic class as a teacher and here I am learning a lot in a half hour video. I'm not that old but felt like 80y old easy.
    Very good tip, love the intros and explanations (I want to understand, not just copynpaste).
    sometimes its a bit too fast for someone that dont open a dev env since delphi 6 like me, those ctrl + ( . ) and tab autofill put me crazy sometimes, but nothing that a stop and 5 sec rewind dont solve.
    thanks!
    (sorry for my poor eng).

  • @dense3d
    @dense3d 5 років тому +1

    Crystal clear explanation. Exactly what I was looking for!

  • @chandana4554
    @chandana4554 4 роки тому

    Thank you Tim. I did watch few different videos on this same topic. But this was simply the best. You explained the concept, the tools and the process so clearly and effectively. The idea of creating a console app instead of using the service project is brilliant. It saves so much time in debugging when we do a complicated service. Thanks mate. Much appreciated.
    BTW, it would be great if you could do a follow up video on using Squirrel with this project.

    • @IAmTimCorey
      @IAmTimCorey  4 роки тому +1

      Glad it was helpful! Thanks for the suggestion.

  • @abrahameduardoordoricaisla9103
    @abrahameduardoordoricaisla9103 2 роки тому

    I'm pretty sure that you've listened this many times. You rock bro! His video helped to me so much, can you make a video talking about the services recovery options?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      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/

  • @beerguy1320
    @beerguy1320 3 роки тому

    This was very useful!! I have to digest TopShelf into my brain a bit but I really appreciate the console app setup!! Thank you.

  • @IyaTaisho
    @IyaTaisho 5 років тому

    This was a very helpful video. It truly gave me all the help I needed in getting a service stood up that runs once a day at 4 AM. Great job!

  • @sothecominternational8973
    @sothecominternational8973 3 роки тому

    Always nice to come back to this even if for a quick refresher

  • @tamboleo
    @tamboleo 4 роки тому

    Thank you very much! I am learning C# and i wanted to create a service for deleting a regedit folder if exists, i didn't know the language used on Windows services was c#. So this makes me learn it even more :D

  • @ben.thornhill
    @ben.thornhill 5 років тому

    Your content is some of the best out there on any subject. Thank you so much!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      I appreciate the kind words.

  • @larrye
    @larrye 5 років тому

    Great! I was struggling trying to create a Windows Service using the template and this helped a lot.

  • @PatricSjoeoe
    @PatricSjoeoe 5 років тому

    Hi Tim! Excellent video as always! My best tip to debug an ordinary win service project is use of #if debug in program.cs and call to same "start method". It works perfectly for me :)

  • @davidramirez3322
    @davidramirez3322 5 років тому

    Wooouu!! Tim u are the man! I am really happy to know to do this, I could do it on my own compu, its awesome !!! how easy you explain it, ! tons of gratitude. my first services!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Awesome! Congrats on your first service!

  • @alexwerges3766
    @alexwerges3766 3 роки тому

    Thank you for this wonderful video. I was running into some serious roadblocks in rewriting a windows service at my current workplace due to the Microsoft project template making it difficult to debug initialization steps. Also, I totally agree with the text logging being an issue on long running windows services, since the person who wrote the old one was using text logging and it was blowing up the system despite changing to a new text file daily.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      Thanks for sharing that real world example.

  • @tommyoman5309
    @tommyoman5309 2 роки тому

    Thanks again Tim! I was thinking about saving the day to day wallpaper-pictures coming from bing somewhere to keep them (sometimes very nice pics) , This will be the way ! So many good things coming from you ! Best Regards !

  • @josephmarsh5031
    @josephmarsh5031 5 років тому

    Super useful. I love your idea of using a service to perform file maintenance! :)

  • @rodrigo6459
    @rodrigo6459 5 років тому

    This video “inspired me” to actually implement the “download folder keeper” as a service, and I’m almost done, if any one is interested I will be uploading probably tomorrow the source code to github, I used what Tim tough in a video about directories but I also implemented a way to find the “default” download folder for your computer. Also used the “app.conf” as Tim also did as a challenge a few weeks ago.
    Thanks once again Tim... you had built a great community to share knowledge and learn!

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      I'm glad you are making use of what you learn.

    • @rodrigo6459
      @rodrigo6459 5 років тому

      Okay guys... the project is up, all you have to do is download, compile and install. So far the thing is working for me!
      github.com/acidrod/DownloadsKeeper

  • @parasrawat7287
    @parasrawat7287 3 роки тому

    Such an elegant way of explaining things... Awesome dude

  • @Shinika01
    @Shinika01 5 років тому

    it's been a while i didn't stop here :) Happy i did today!
    Thanks, usefull stuf (veeeerry usefull) well explained as usual!
    I like that format you have for a while, quick snipet from A to Z with amazing (basic) ideas :) Thanks

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Thanks for the feedback. I'm glad you are enjoying the content.

  • @groch94
    @groch94 5 років тому +1

    Great video, hope for more about services and communication between services and applications!

  • @chunkyazian
    @chunkyazian 3 роки тому +1

    Definitely deserves a like. However, I recently had to implement a service for work and I got the 1053 error when I started it. What it said was
    "The service did not respond to the start or control request in a timely fashion"
    Instead of writing the following start method as mentioned in your video
    public void start()
    {
    //instantiate a bunch of objects and running through the constructors
    }
    I use start to call async codes as the following
    public void start()
    {
    _callStartTasksAsync();
    }
    private async Task _callStartTasksAsync()
    {
    await Task.Run(()=>{ //instantiate a bunch of objects and running through the constructors } )
    }
    This allowed the service to get through the start method ASAP and avoided the error

  • @Robd515
    @Robd515 Рік тому

    Excellent video!! Thank you very much for the quality content Tim

  • @thejourney4609
    @thejourney4609 5 років тому

    Wow! Such a great tutorial and beautifully explained!

  • @heroesch
    @heroesch 5 років тому

    You are a great instructor Tim! Keep it up... 👍🏻

  • @Bilalkhan-pf8xg
    @Bilalkhan-pf8xg 2 роки тому +1

    This is so useful and well explain thing to learn today, you are the best Tim

  • @garyburch1907
    @garyburch1907 5 років тому

    Very helpful. I always have trouble with brown outs in my area and I have a plex server running in my basement. If I am out of town, the server would restart but the plex software would not. I created a service called to launch plex when the server rebooted automatically. Works perfect.

  • @charlesm.1638
    @charlesm.1638 4 роки тому

    Thank you for this great video. My goal from what I learned from your video is that I need to do check specific equipment on my network to make sure they are running and provide updates on the status of the equipment say for example every 10 minutes I would like my service to check the equipment every 10 minutes by doing a ping test to see if there is a return if there is no return the change the status code to indicate this. The information will update a database table as changes occur. I figured having running a Windows service is better than using a task manager to perform the job.

  • @gauravparvat5291
    @gauravparvat5291 5 років тому

    Thanks a lot for responding to my comment. Now the font and colour are clearly visible even in my phone.

  • @FEYSCONTROL
    @FEYSCONTROL 5 років тому

    Thanks Tim! Did the job nicely and smoothly.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Thank you!

    • @FEYSCONTROL
      @FEYSCONTROL 5 років тому

      @@IAmTimCorey Hi Tim, I could suggest an idea to create a video showing how a service can get the permissions in order to launch applications as this was my initial goal. It appeared the OS sessions doesn't allow that by default but I read it is achievable.

  • @eliasdargham
    @eliasdargham 2 роки тому

    Thanks for another great video tim!
    I'm using trying to use a service to listen on a socket server from a large number of client connections. The goal is to be able to run a scheduler on these clients and take their payload to store it in a central database.

  • @MrRicardovws
    @MrRicardovws 4 роки тому

    Great tutorial! It help me a lot with a project that I had to create a service that makes a data copy from Arduino to a MySQL database.

  • @avitwito1734
    @avitwito1734 5 років тому +1

    Great tutorial as usual. Thank you

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are most welcome. Thanks for watching.

  • @SudarshanKrSingh
    @SudarshanKrSingh 3 роки тому

    Thanks Tim , so much to learn from your videos.

  • @WSDFirm
    @WSDFirm 3 роки тому

    Excellent explanation. Thanks, I was able to type along and understand.

  • @lelanceflamer
    @lelanceflamer Рік тому

    Hello, I love your tutorials I want to thank you for those! It was very interesting! So I can build my own Windows Service project or install the service automatically. Thank you for explaining what everything does.

  • @TheBus1234
    @TheBus1234 5 років тому

    Excellent tutorial, learned more than expected

  • @joseisraelfloresguzman75
    @joseisraelfloresguzman75 Рік тому

    Thank you, this video was very helpful. With this my project worked smoothly.

  • @luizhdsbr
    @luizhdsbr 2 роки тому

    This a life saver. It made my job so much easier, thanks for that!!!

  • @ogmiga
    @ogmiga 5 років тому

    This works great. Got this Just In Time.
    Very helpful. Thank you

  •  5 років тому

    Thanks Tim! Finally I can abandon my holy trio consisting of Windows service for production, console application for debuging and class library handling all the fun. Service and console app were very simplistic. Just start and stop Task provided by class library.

  • @benshkabanka9044
    @benshkabanka9044 2 роки тому

    great Video! I always Use Windows Service Project. When I do this, I always create a second project in the same solution with a simple GUI, to trigger the same methods as the service does, when I need to debug it. That also works pretty well, but maybe I will try this solution in the future.

  • @stanislavbozhikov9046
    @stanislavbozhikov9046 2 роки тому

    Very good .. I was thinking about parsing a text file automatically to database . and Now I get it .. thanks for the tip

  • @antoniocouto7092
    @antoniocouto7092 2 роки тому

    Thanks a lot for the video, even now after these years help me a lot. Regards.

  • @meenubala-br7vo
    @meenubala-br7vo 2 роки тому +1

    Well explained. Thank you for sharing

  • @summerbreeze25syria
    @summerbreeze25syria 3 роки тому

    I really liked the idea of organizing pictures. I will use it for organizing my desktop.

  • @lucas1984FD
    @lucas1984FD 4 роки тому

    Tim is a wonderful tutorial. Thanks

  • @acidhauss7018
    @acidhauss7018 5 років тому +1

    Great video, nice introduction to a topic I knew absolutely nothing about.
    I'd love to see a video on using Github within Microsoft Visual Studio for a simple project. The older one is good but think one using the actual baked-in functionality would be very helpful.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      Something close to that is coming soon in a course. I'll be covering GitHub at some point as well.

  • @bssns
    @bssns 5 років тому

    Many thanks, sumptuous and very clear ...

  •  4 роки тому

    Amazing video, thanks for the help! Keep doing the good work, it helps us a lot! :D

  • @Manithan123
    @Manithan123 5 років тому

    Amazingly clear!

  • @ajayseal9990
    @ajayseal9990 5 років тому

    Very nice tutorial I got my solution, Thanks Lot Tim and looking more from you thanks again

  • @MCcrafterDE
    @MCcrafterDE 4 роки тому

    You´re awesome, really perfect understanding!

  • @MrSuddens
    @MrSuddens Рік тому

    Thank you! I will be making an API connector to check for updates in my SQL database table and post them via API.

  • @wisbenah
    @wisbenah 5 років тому

    Thanks, Tim, great video as always.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are most welcome. Thanks for watching.

    • @wisbenah
      @wisbenah 5 років тому

      @@IAmTimCorey What version of NotePadd++ are you using? I couldn't find that "Monitoring" feature you mentioned in the video.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      7.4.2 - I believe I'm actually a couple versions behind

  • @waynehawkins654
    @waynehawkins654 3 роки тому

    Excellent. Thank you for this. I a web coder and needing a Services project to do SQL things. Big help :)

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      Glad it helped!

    • @waynehawkins654
      @waynehawkins654 3 роки тому

      Be good to see a video that expands on this one to show a simple toolbar icon that allows you to start\stop services and maybe open a window that allows one to change a setting.

  • @nestorvalleser6275
    @nestorvalleser6275 7 місяців тому

    Thanks for sharing your code and knowledge. This will help me a lot... God bless!

  • @peadarfitzpatrick3287
    @peadarfitzpatrick3287 5 років тому

    Great tutorial as always Tim! Very useful!

  • @ismailjama7440
    @ismailjama7440 2 роки тому

    Thanks a lot Tim, you are the best

  • @babeyoshafiq
    @babeyoshafiq 5 років тому

    thanks for the clear explanation.

  • @rileynobles7146
    @rileynobles7146 2 роки тому

    Very nicely done video, Thanks

  • @pauljohns5447
    @pauljohns5447 5 років тому +1

    Amazing. Thank you.

  • @balasubramaniyanjayachandr1186
    @balasubramaniyanjayachandr1186 4 роки тому

    Thank you! This is very helpful!

  • @Ekas_
    @Ekas_ 2 роки тому +1

    Wow this is crazy useful

  • @SR-bv1we
    @SR-bv1we 5 років тому

    This is amazing. Thank you so much.

    • @IAmTimCorey
      @IAmTimCorey  5 років тому

      You are most welcome. Thanks for watching.

  • @dreamvallyhasan4807
    @dreamvallyhasan4807 3 роки тому +1

    Thanks for excellent video

  • @steliosvasiliadis3480
    @steliosvasiliadis3480 3 роки тому

    Great video! We use this technique to export web services

  • @phongkien
    @phongkien 4 роки тому

    Thank you very much for your tutorial.

  • @insomnia8692
    @insomnia8692 5 років тому

    In File Explorer in the address bar you can just type "cmd" and it will open cmd to that directory. Great video by the way, still trying to think of some ideas on how to use this!

  • @jgoungs
    @jgoungs 3 роки тому

    Very good tim. God bless you

  • @valeryngwa
    @valeryngwa 4 роки тому

    Awesome Tutorial

  • @Gimmiyimmy
    @Gimmiyimmy 4 роки тому

    Nicely Explained.

  • @benid696
    @benid696 3 роки тому

    Very helpful, thank you!

  • @brucelinmichael341
    @brucelinmichael341 4 роки тому

    thankyou very much,it is a simple and good sample.

  • @LinaScott
    @LinaScott 4 роки тому

    Thank you very much. This video helped me setup my very first service using a language i am very unfamiliar with but now am building an idea of how to use. :)
    Next trick... either counting the output files or switching file names when it reaches the next day? Hmmm ...

    • @IAmTimCorey
      @IAmTimCorey  4 роки тому +1

      Awesome! I am glad it was so helpful.

  • @dammieoptimus
    @dammieoptimus 5 років тому

    Great tutorial. Thanks

  • @dorbenmoyal7639
    @dorbenmoyal7639 3 роки тому

    Thanks, Like your videos, simple and clear :-)

  • @vidyasagarpamula794
    @vidyasagarpamula794 5 років тому

    Excellent Video

  • @Evilbotftw
    @Evilbotftw Рік тому

    A great video indeed , Ideas in the ending are amazing though.

  • @ana-mariaolujic6570
    @ana-mariaolujic6570 2 роки тому

    Very useful, thanks!

  • @duongchinhngu2407
    @duongchinhngu2407 11 місяців тому

    A million thanks. It's great.

  • @lakhanbisht7334
    @lakhanbisht7334 4 роки тому

    Tim , this is a great tool