Virtuesoft.Framework.WindowsService 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Virtuesoft.Framework.WindowsService --version 1.1.0
                    
NuGet\Install-Package Virtuesoft.Framework.WindowsService -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Virtuesoft.Framework.WindowsService" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Virtuesoft.Framework.WindowsService" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Virtuesoft.Framework.WindowsService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Virtuesoft.Framework.WindowsService --version 1.1.0
                    
#r "nuget: Virtuesoft.Framework.WindowsService, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Virtuesoft.Framework.WindowsService@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Virtuesoft.Framework.WindowsService&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Virtuesoft.Framework.WindowsService&version=1.1.0
                    
Install as a Cake Tool

新建控制台程序

class Program { static void Main(string[] args) { new WindowsServiceHostBuilder() //默认app.json 文件配置 .UseConfigure() //采用对象进行配置 文件配置和对象配置二选一 .UseConfigure(option ⇒ { //是否桌面交互 option.IsDesktop = true; option.ServiceName = "服务名称"; option.Display = "显示名称"; option.Description = "详细描述"; //启动方式 option.StartOption = StartOption.auto; }) //控制台日志 .UseConsoleLogging() //文件日志 .UseFileLogging() //使用IO注入使用服务 .UseSingleton<SampleService>() //.UseTransient<SampleService>() //注入服务 .UseWindowsService<log>() //注入服务 .UseWindowsService<logSmart>() .Build() .Run(args); } }

//创建服务和对象 public class SampleService { /// <summary> /// 使用 IConfiguration 需要使用文件配置 /// </summary> /// <param name="logger"></param> /// <param name="configuration"></param> public SampleService(ILogger<SampleService> logger, IConfiguration configuration) {

    }
}
public class log : IWindowsService
{
    ILogger<log> Looger { get; }
    public log(ILogger<log> looger,IServiceProvider serviceProvider) => Looger = looger;
    public string Name => "Testing.Log";

    public string Display => "测试服务";

    public Task<bool> PauseAsync(CancellationToken cancellationToken = default)
    {
        return Task.FromResult(true);
    }

    public Task<bool> StartAsync(CancellationToken cancellationToken = default)
    {
        //Looger.LogInformation(DateTime.Now.ToString("HH:mm:ss fff"));
        _=Task.Run(async () => {
            while (true)
            {
                await Task.Delay(1000);
                var configuare= this.GetService<WindowsServiceConfigure>();
                Looger.LogInformation($"{configuare.ServiceName}:=>{DateTime.Now.ToString("HH:mm:ss fff")}" );
            }
        });
        return Task.FromResult(true);
    }

    public Task<bool> StopAsync(CancellationToken cancellationToken = default)
    {
        return Task.FromResult(true);
    }
}
public class logSmart : IWindowsService
{
    ILogger<logSmart> Looger { get; }
    public logSmart(ILogger<logSmart> looger) => Looger = looger;
    public string Name => "Testing.logSmart";

    public string Display => "测试服务";

    public Task<bool> PauseAsync(CancellationToken cancellationToken = default)
    {
        return Task.FromResult(true);
    }

    public Task<bool> StartAsync(CancellationToken cancellationToken = default)
    {
        Task.Run(async () => {
            while (true)
            {
                await Task.Delay(2000);
                Looger.LogInformation(DateTime.Now.ToString("HH:mm:ss fff"));
            }
        });
        return Task.FromResult(true);
    }

    public Task<bool> StopAsync(CancellationToken cancellationToken = default)
    {
        return Task.FromResult(true);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Virtuesoft.Framework.WindowsService:

Package Downloads
Virtuesoft.Framework.WindowsService.WindowsHost

windows服务框架

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.3 1,009 8/8/2022
6.0.2 1,109 2/9/2022
6.0.1 1,049 2/8/2022
6.0.0 1,066 1/24/2022
1.1.6 916 9/13/2021
1.1.5 978 7/28/2021
1.1.4 929 7/28/2021
1.1.3 941 7/28/2021
1.1.2 937 7/28/2021
1.1.1 937 7/27/2021
1.1.0 927 7/27/2021
1.0.9 960 7/27/2021
1.0.8 930 7/27/2021
1.0.7 956 7/26/2021
1.0.6 921 7/26/2021
1.0.5 949 7/25/2021
1.0.4 981 7/25/2021
1.0.2 962 7/25/2021
1.0.1 1,006 5/8/2021
1.0.0 999 5/7/2021