Asp.net core 托管服务

开发工具visual studio 2022

框架 .net 6

用asp.net core 写上位机程序,需要使用tcp通讯,

自己写个后台服务类,只要继承BackgroundService类即可 

使用起来非常方便


namespace StraightLineSorting.Service
{
    public class HostedService:BackgroundService
    {
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            LogHelper.Debug("连接TCPClient");
            TcpSupersocket.GetInstance().Connect();
            await Task.Delay(1);
        }
    }
}

program.cs中加入下面代码即可 

builder.Services.AddHostedService();

你可能感兴趣的:(asp.net,core,java,开发语言)