Virtuesoft.Windows.Services
1.1.3
dotnet add package Virtuesoft.Windows.Services --version 1.1.3
NuGet\Install-Package Virtuesoft.Windows.Services -Version 1.1.3
<PackageReference Include="Virtuesoft.Windows.Services" Version="1.1.3" />
paket add Virtuesoft.Windows.Services --version 1.1.3
#r "nuget: Virtuesoft.Windows.Services, 1.1.3"
// Install Virtuesoft.Windows.Services as a Cake Addin
#addin nuget:?package=Virtuesoft.Windows.Services&version=1.1.3
// Install Virtuesoft.Windows.Services as a Cake Tool
#tool nuget:?package=Virtuesoft.Windows.Services&version=1.1.3
布德软件windows服务集合框架
https://blog.csdn.net/ouyanghanwen/article/details/108228153
新增获取宿主中多个服务
修改即时方式
Product | Versions 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Newtonsoft.Json (>= 12.0.3)
- System.ServiceProcess.ServiceController (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
布德软件windows服务集合框架
class Program
{
static void Main(string[] args)
{
foreach (var a in args)
Console.WriteLine(a);
//实例化宿主程序
new ServiceHost()
//配置当前服务
.Config(option=> {
//名称
option.Name = "virtuesoft.windows.service.framework";
//简述
option.Display = "";
//详细
option.Description = "";
//加载配置
option.UseConfig(c => c.Path = "h.json");
})
//注册服务
.Register<TestionService>(option=> {
//配置参数
option
.Add("key1", "value1")
//加载配置
.UseConfig(config =>
{
config.Path = "http://res.b.cn/c.json";
});
})
//启动服务
.Start(args);
}
}
新建服务
public class TestionService : IWindowsService
{
//名称
public string Name { get; } = "virtuesoft.app.notify";
//简介
public string Display { get; } = "app消息通知服务";
private string Folder { get; set; }
/// <summary>
/// 服务启动
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public bool Start(ServiceContext context)
{
Folder = Path.Combine(context.StartPath,"db");
if (!Directory.Exists(Folder)) Directory.CreateDirectory(Folder);
Task.Run(async () => {
while (true) {
await MakeBlock();
context.Log("执行成功");
await Task.Delay(new Random(Guid.NewGuid().GetHashCode()).Next(1*60*1000,5 * 60 * 1000));
}
});
return true;
}
/// <summary>
/// 服务停止
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public bool Stop(ServiceContext context)
{
context.Log("服务停止");
return true;
}
private async Task MakeBlock() {
var path = Path.Combine(Folder, $"{DateTime.Now:mmddHHmmssfff}");
var radom = new Random(Guid.NewGuid().GetHashCode());
int[] moneys = new int[] { 10, 20, 50, 100 };
//值
var m = moneys.OrderBy(t => Guid.NewGuid()).First() ;
//时间
var tickes =DateTime.Now.Ticks;
//生成机器
var mchint= Guid.NewGuid().ToByteArray();
using (var sw = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
{
using (var bw = new BinaryWriter(sw, Encoding.UTF8))
{
bw.Seek(0, SeekOrigin.End);
bw.Write(m);
bw.Write(tickes);
bw.Write(mchint);
}
}
}
}