Windows Service in .NET Core | How to create, install, and use a service

Поділитися
Вставка
  • Опубліковано 11 жов 2024
  • #windowsService
    In this video, we are going to look at how to create a Windows Service in .NET Core , how to run and how to install it.
    .NET Core is a free and open-source, managed computer software framework for Windows, Linux, and Mac operating systems. It is an open source, cross platform successor to .NET Framework.
    For more details about .NET Core Windows Service Please check below link
    docs.microsoft...
    Windows Service command for .NET Core is as follows
    Install-Package Microsoft.Windows.Compatibility
    (i) To publish as Release version
    dotnet publish --configuration Release
    (ii) To Create the Service
    sc create YourServiceName binPath= "YourpathName+ServiceName.exe"
    (iii) To start/install the Service
    sc start YourServiceName
    (iv) To delete/uninstall the Service
    sc delete YourServiceName
    Don't forget to subscribe "CoreProgramm" !
    Website : www.coreprogra...
    Facebook : / coreprogramm
    Twitter : / coreprogramm
    Instagram : / thecoreprog. .
    Github : github.com/Cor...
    Linkedin : / coreprogramm
    The Source Code is available in Github :
    github.com/Cor...
    For more details about the topic please visit CoreProgramm Website:
    www.coreprogra...

КОМЕНТАРІ • 21

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

    Hope it clear about how to create and install/uninstall windows service in .NET Core !! Do LIKE & COMMENT to let us know your feedback🔥

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

    Do I need to remove a Windows service when developing a later version? It may be possible to reinstall instead of a previously installed one.
    If yes, how to do it if not, how to remove the previously installed service ?

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

    Thanks!!! Nice tutorial. When the service is running doesn't update the txt file, to fix this only change the method
    public void Onstart(string[] args)
    for :
    protected override void OnStart(string[] args)

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

    great video.
    i think, it would be better if you would add a project for installer to setup the service.

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

      Thanks for your suggestion. Sure we should prepare a video of installer setup. Please stay tune.
      Thanks again for your feedback !!

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

      @@JayantT Great video. However, now it is all about .NET Core 3.1 and 6.0. This tutorial is great but is outdated.
      It is frustrating that the minute you learn something new, the next minute it is outdated.
      It is likely never-end learning.
      In SQL world, things remain constant for a long time.

  • @SaravananSubbiah-ls4ep
    @SaravananSubbiah-ls4ep Рік тому

    I think, it would be better if you would add a project for installer to setup the service

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

      Thanks for your suggestion. Will try to make a video on this.

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

    HI. Tanks for your tutorial , but after the service was start, it the log text file could not be update.

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

      Pls check once your thread/timer is running or not. Usually we configured the time interval and upon reach the time the service call the method again and Log text should work with pushing new text.

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

    How to install windows service created in localsystem on remote server

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

    How to inject logger and configuration dependency for filewriteservice class?

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

      Hey komal, Using below code you can inject the logger for file-write service.
      using Microsoft.Extensions.Logging;
      public class Startup
      {
      private readonly ILogger _logger;
      public Startup(IConfiguration configuration, ILoggerFactory logFactory)
      {
      _logger = logFactory.CreateLogger();
      Configuration = configuration;
      }
      public IConfiguration Configuration { get; }
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
      _logger.LogInformation("Welcome to CoreProgramm");
      }

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

    That service is running manually....how can we make that service to run automatically???

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

      In Project installer we can override the method OnAfterInstall and this make the service run automatically. Please follow the CoreProgramm Blog to see the code.
      www.coreprogramm.com/2019/09/start-windows-service-automatically.html

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

    how to add services like services.AddDbContext in windows service?

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

      You can add the service.AddDbContext class library .NET Core following below steps.
      Simply create a extension method like below
      public static class MyExtension {
      public static IServiceCollection AddMyLibraryDbContext(this IServiceCollection services, IConfiguration Configuration) {
      services.AddDbContext(options => options.UseSqlServer(Configuration["ConnectionStrings:YourConnectionString"]));
      return services;
      }
      }
      Now call that extension is startup.cs
      public class Startup {
      public void ConfigureServices(IServiceCollection services) {
      //...
      services.AddMyLibraryDbContext(Configuration);
      services.AddMvc();
      }
      }
      Remember that you need to be install Microsoft.EntityFrameworkCore.SqlServer to use options.UseSqlServer extension in dependency injection.

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

    Can you share github link for codebase?

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

      Please go through the source code link github.com/CoreProgramm/Windows-Service-.NET-Core
      Also you can go through article as well.
      www.coreprogramm.com/2019/08/how-to-create-windows-service-in-net.html?m=1