I worked on my own little project for a full day. It would run fine from Visual Studio but as a Service it would time out and would not start. This was just from the very basic example that Visual Studio creates for you. I did not know you had to add the WindowsServices library. As soon as I did that and updated the program.cs, it worked like a charm. You saved me from crying. Thank you.
@adeni43592 жыл бұрын
Love your channel. Please more long tutorials!
@RoundTheCode2 жыл бұрын
Thanks Adeni
@dylanmckay1369 Жыл бұрын
Thanks for the help. This worked beautifully. Better than the Microsoft Tutorial.
@RoundTheCode Жыл бұрын
Glad it helped Dylan!
@edvardpotapenko2 жыл бұрын
Thank you! Clear and simple
@RoundTheCode2 жыл бұрын
Thanks Edvard.
@aniljain502 жыл бұрын
Simple and excellent tutorial
@RoundTheCode2 жыл бұрын
Thanks Anil
@gahshunker3 ай бұрын
how can this made cross platform? any nuget package to have a host that is not windows specific? great video btw, concise and to the point. thanks
@tommykahlow53532 жыл бұрын
Thank you for the tutorial! I wasn't adding in the Microsoft.Extensions.Hosting.WindowsServices to my project and I couldn't figure out why my service was failing to start. It would run and log for 30 seconds and then quit with a message saying "The service did not respond to the start or control request in a timely fashion."
@RoundTheCode2 жыл бұрын
Yes it can be hard to debug Windows Service's. Glad you managed to resolve the issue.
@softscrypt8474 Жыл бұрын
When I run the consul, information is written in the logger @Round The Code
@fedorpinega25072 жыл бұрын
Thanks for info, it allowed me to created my service. Special thanks for subs ;) Keep up the good work!
@hassannoor61852 жыл бұрын
Is there a follow up video on this topic?
@RoundTheCode2 жыл бұрын
Hi Hassan, What follow up video are you expecting?
@bioanu2 жыл бұрын
Thank you!! Excellent stuff! It is possible to add a SignalR hub server to our Worker service??
@RoundTheCode2 жыл бұрын
Hi bioan, A SignalR Hub requires a URL so clients can connect to it. As a .NET Worker Service is a background service rather than a web application, I would assume that you can't. However, you can run hosted services in ASP.NET Core and that would work. You could pass in your IHubContext into your hosted service as it has a Singleton service lifetime. Check out this video for more about ASP.NET Core hosted services. kzbin.info/www/bejne/f5bOoIifpJd5m80
@bioanu2 жыл бұрын
@@RoundTheCode Thank you very much!!!
@coding-gemini9 ай бұрын
Nicely explained Thank you, what are the other options for making it an automatic windows service, auto ?
@RoundTheCode8 ай бұрын
What exactly do you mean?
@shreyasmahajan21574 ай бұрын
In my case everything worked perfectly as demonstrated except the deployment part. After creating the service using "sc" command, I am getting the following error : Windows Could not start the service on the local computer. Error 1053 : The service did not respond to the start or control request in a timely fashion. What is the reason for this error ? Thanks.
@RoundTheCode4 ай бұрын
You've either got the service name wrong, or there is a bug with your application. Make sure the service name you ran with the "sc" command matches what is in your app.
@shreyasmahajan21574 ай бұрын
@@RoundTheCode Thanks for the reply!! Here is the the the way I am creating the service : sc create AIQuestionGeneration.WorkerService binpath="D:\Path\ToService\Build1\AIQuestionGeneration.WorkerService.exe" start="demand" displayname="AIQuestionGeneration.WorkerService" Any thing incorrect ? Or a Bug in my application ?
@shreyasmahajan21574 ай бұрын
After banging my head for quite a few hours, I have sorted the issue. The issue was simple, the service was not able to find the app.settings.json file because I had used "Directory.GetCurrentDirectory()" in my Program.cs. As a result it was searching the file in the default location of system32. All what I had to do was change the path to : "Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)" and it worked in a second. The error which I got was not much informative. I had to visit the "Event Viewer" section in Windows to check the logs and figure out the exact error.
@denissmith8282 Жыл бұрын
Nice and easy, thank you. Btw, you look like a South Park character prototype 🙂
@RoundTheCode Жыл бұрын
Respect mah authoritah!
@moussakecibi17402 жыл бұрын
I like your video. But I have a question whom will send the cancellation token to workerservice? and whats thw role of the loop while? is it to keep the WorkerService running? Thank you in adavnce
@RoundTheCode2 жыл бұрын
Yes, the loop is to keep the Worker Service running. I believe the application will automatically send the cancellation token to the Worker Service when it stops.
@JanManipol27 күн бұрын
Thanks for the help. You're a savior.
@siavashmehmandoost2198 Жыл бұрын
Thank you for the great tutorial! Is there any way to keep our windows service running even in sleep or hibernate mode? I just created a windows service and it's suspended (not stopped!) when I close the lid of the laptop.
@RoundTheCode Жыл бұрын
I'm not aware of anyway of doing it. If your computer is asleep, surely you wouldn't want it to be running any services?
@pillockmacpillock24633 ай бұрын
Not sure I like this implementation. Where are the classic start and stop stubs you get in framework? Feels like the core version is a bit noddy
@RoundTheCode3 ай бұрын
Are you talking about the WorkerService? It inherits the IHostedService interface which includes StartAsync and StopAsync methods. These can be overloaded through the WorkerService. This video has more details about it: kzbin.info/www/bejne/rZfcon6OgsuNfs0
@bill_19512 жыл бұрын
.Net Framework services are able to receive custom commands via "protected override void OnCustomCommand(int Command)". Is equivalent functionality available in .Net 6? I've looked at many examples of creating .Net 6 Worker Services but they all seem to use timers to monitor or report something periodically, none of the examples show receiving custom commands from other applications.
@RoundTheCode2 жыл бұрын
Have a look at this. It might be what you're after? github.com/dotnet/runtime/issues/50021#issuecomment-547503684
@snldev Жыл бұрын
I've developed a routine that reads/updates data from specific database and then do a looping in the rows and returns status information to another application (webhook). It repeats every 24 hours. It works in this BackgroundService approach, but is it a good pratice? There is no much data read in this process, I guess about 150 per day. Thanks
@RoundTheCode Жыл бұрын
Hi Leivas. It sounds good to me. Is it 24 hours after the app has started? Or is it at a specific time of day?
@snldev Жыл бұрын
@@RoundTheCode it's at a specific time of day
@guswind46362 жыл бұрын
What if you would need to call another Background service from the main Worker Service?
@RoundTheCode2 жыл бұрын
Hi Gus, Would you want to trigger a background service to start from another Worker Service? Is that what you're asking?
@guswind46362 жыл бұрын
@@RoundTheCode Yes I have one Hosted Worker Service that runs initially and at some point of its execution I want to start another "child" background process. I'm currently triggering the child process with "await Task.Run(() => ChildBackgroundProcess, cancelToken)" but I'm not sure whether that is the correct\clean way to do it
@RoundTheCode2 жыл бұрын
@@guswind4636 And I'm assuming you didn't add the child background process to the IoC/DI container as part of dependency injection? You just created a new instance of the child background process and ran it?
@guswind46362 жыл бұрын
@@RoundTheCode yes I didn't add the child process to the DI container, it's just a child Process\Task that runs indefinitely as long as the main Worker Service runs
@RoundTheCode2 жыл бұрын
@@guswind4636 I personally don't see anything wrong with that, as long as the two tasks have some sort of relation, and the child task has to run on the parent task.
@mikopanjean87562 жыл бұрын
Most Usefull Tutorial. Thank You!!
@RoundTheCode2 жыл бұрын
Thanks for the comment, Miko.
@faridulhuk12482 жыл бұрын
Hi can we add multiple job into the worker service using (Quartz)
@RoundTheCode2 жыл бұрын
I've never used Quartz before, but I'm assuming you can do it.
@richardokonicha2 жыл бұрын
Hi @roundtheCode, could we have work services in a different language like python on azure? I have been struggling with this for a while
@RoundTheCode2 жыл бұрын
Hi Richard, unfortunately I don't know enough but Python to be able to answer your question.
@peterwilson712 жыл бұрын
I have a worker service and added the Setup Installer project but I haven't found a way to install the service using the installer. It works with sc.exe but how can I add this step to the installer?
@RoundTheCode2 жыл бұрын
You could have a look at the WiX Toolset. I have created installers for .NET Framework services in the past. Guessing you could use it for later .NET versions? wixtoolset.org/
@toniobrados67362 жыл бұрын
Good video... Is possible to make this service in an unstoppable service? Thanks
@RoundTheCode2 жыл бұрын
Hi Toni, Thanks for your comment. Just out of interest, why would you want an unstoppable service?
@toniobrados67362 жыл бұрын
@@RoundTheCode Because the user should not stop it. It is a service that takes statistics from the computer.
@RoundTheCode2 жыл бұрын
@@toniobrados6736 Check out this StackOverflow post. A user has come up with a possible solution. stackoverflow.com/questions/70503859/is-there-a-way-to-disable-the-stop-button-in-windows-worker-services-background
@duongchinhngu24079 ай бұрын
Thank you so much, your video saved my day!
@RoundTheCode9 ай бұрын
You're welcome!
@PremKumar-kg5ep2 жыл бұрын
Very good explanations.
@RoundTheCode Жыл бұрын
Thanks for your comment.
@stilllearningknowledge45292 ай бұрын
Thank you. Clear and simple. Nice explanation. Keep going
@RoundTheCode2 ай бұрын
Thank you, I will
@CamiloMejíaMonsalve Жыл бұрын
thank you so much man, for your videos, for the time and the love that you put in them, you are pretty helpful for me
@RoundTheCode Жыл бұрын
Thanks Camilo. Glad you are enjoying the content.
@jps9355 Жыл бұрын
I am getting error 193 when i try to start the service. When i try to start it from the console it says that it is not a valid win32 aplication. Does anyone know what could be causing it?
@RoundTheCode Жыл бұрын
I would check that you have the correct filepath to the .exe file when you registered the Windows Service. If the filepath doesn't match, you are likely to see an error like that.
@imterpsfan210 ай бұрын
Nice example. I have an existing Windows Service application in .NET Framework that I'm migrating to a Worker Service. Because I am using some Windows-specific aspects in the service, such as reading Windows Event Logs (EventLogQuery) I'm assuming I will need to encapsulate this functionality in the .NET Standard and then reference that project in the worker service? Wait, I see System.Diagnostics.EventLog ia now in nuget package manager as a .NET Platform service so maybe I don't need to do this trick anymore? The answer is that I don't need to encapsulate the project in .NET Standard and then reference in .NET Core. I can do it directly! But I need the Windows Compatibility Pack. dotnet add package Microsoft.Windows.Compatibility --version 8.0.0 dotnet add package System.Diagnostics.EventLog --version 8.0.0
@RoundTheCode10 ай бұрын
Looks like you've found out how to do it.
@mhsn27mhsn1029 күн бұрын
thank you Sir
@khaqankhokhar3543 Жыл бұрын
great explaination
@RoundTheCode Жыл бұрын
Thanks Khaqan
@UnknownMoses2 жыл бұрын
In file explorer, if you hold Shift + Right Click, the context window gives you an option, "copy as path" this copies the full file path inside double quotes, so you can paste it anywhere. Annoyingly, in Windows 11, you probably have to click, show more options on the dumb Windows 11 context menu.