using DevicesService.Commen; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using System; using System.IO; using System.Threading.Tasks; namespace DevicesService { internal class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { // 更改为你想检查的进程名称 //new COMUtils(); //启动静态服务器 Task.Run(() => { WebHost.CreateDefaultBuilder().UseUrls("http://0.0.0.0:5000").ConfigureServices(services => { }).Configure(app => { // 设置静态文件目录 var pathToFiles = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(pathToFiles), RequestPath = "/wwwroot" }); // 处理文件未找到的情况 app.Use((context, next) => { context.Response.StatusCode = 404; return context.Response.WriteAsync("File not found"); }); }).Build().Run(); }); //启动Tcp服务 Task.Run(() => { TcpServer tcp = new TcpServer(); tcp.Start(); }); while (true) { Task.Delay(2000).Wait(); } } } }