ds8-solution-pro/furionDoc/build/assets/js/aa7bdd74.d7727630.js

1 line
38 KiB
JavaScript

"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[4572],{8439:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>l,contentTitle:()=>d,default:()=>x,frontMatter:()=>c,metadata:()=>t,toc:()=>a});var s=n(5893),i=n(1151),o=n(4996);const c={id:"process-service",title:"25. \u8f85\u52a9\u89d2\u8272\u670d\u52a1",sidebar_label:"25. \u8f85\u52a9\u89d2\u8272\u670d\u52a1 (Worker Service)"},d=void 0,t={id:"process-service",title:"25. \u8f85\u52a9\u89d2\u8272\u670d\u52a1",description:"25.1 \u5173\u4e8e\u8f85\u52a9\u89d2\u8272\u670d\u52a1",source:"@site/docs/process-service.mdx",sourceDirName:".",slug:"/process-service",permalink:"/docs/process-service",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/process-service.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1686305520,formattedLastUpdatedAt:"Jun 9, 2023",frontMatter:{id:"process-service",title:"25. \u8f85\u52a9\u89d2\u8272\u670d\u52a1",sidebar_label:"25. \u8f85\u52a9\u89d2\u8272\u670d\u52a1 (Worker Service)"},sidebar:"docs",previous:{title:"24. \u5373\u65f6\u901a\u8baf",permalink:"/docs/signalr"},next:{title:"26. \u5b9a\u65f6\u4efb\u52a1 (Schedule)",permalink:"/docs/category/job"}},l={},a=[{value:"25.1 \u5173\u4e8e\u8f85\u52a9\u89d2\u8272\u670d\u52a1",id:"251-\u5173\u4e8e\u8f85\u52a9\u89d2\u8272\u670d\u52a1",level:2},{value:"25.2 \u5171\u5bbf\u4e3b\u65b9\u5f0f",id:"252-\u5171\u5bbf\u4e3b\u65b9\u5f0f",level:2},{value:"25.2.1 \u6700\u4f73\u5b9e\u8df5",id:"2521-\u6700\u4f73\u5b9e\u8df5",level:3},{value:"25.3 \u72ec\u7acb <code>Worker Service</code> \u65b9\u5f0f",id:"253-\u72ec\u7acb-worker-service-\u65b9\u5f0f",level:2},{value:"25.3.1 \u5982\u4f55\u521b\u5efa <code>Worker Service</code>",id:"2531-\u5982\u4f55\u521b\u5efa-worker-service",level:3},{value:"25.3.2 \u521b\u5efa <code>Worker</code>",id:"2532-\u521b\u5efa-worker",level:3},{value:"25.3.3 \u591a\u4e2a <code>Worker</code>",id:"2533-\u591a\u4e2a-worker",level:3},{value:"25.3.4 \u751f\u547d\u5468\u671f",id:"2534-\u751f\u547d\u5468\u671f",level:3},{value:"25.3.5 \u96c6\u6210 <code>Furion</code>",id:"2535-\u96c6\u6210-furion",level:3},{value:"25.3.6 \u6ce8\u518c\u670d\u52a1",id:"2536-\u6ce8\u518c\u670d\u52a1",level:3},{value:"25.4 \u5b9e\u73b0\u7b80\u5355\u5b9a\u65f6\u4efb\u52a1",id:"254-\u5b9e\u73b0\u7b80\u5355\u5b9a\u65f6\u4efb\u52a1",level:2},{value:"25.4.1 \u95f4\u9694\u6267\u884c\u65b9\u5f0f",id:"2541-\u95f4\u9694\u6267\u884c\u65b9\u5f0f",level:3},{value:"25.4.2 <code>Cron</code> \u8868\u8fbe\u5f0f\u6267\u884c\u65b9\u5f0f",id:"2542-cron-\u8868\u8fbe\u5f0f\u6267\u884c\u65b9\u5f0f",level:3},{value:"25.4.3 \u5b9e\u73b0 <code>\u4e32\u884c</code> \u64cd\u4f5c",id:"2543-\u5b9e\u73b0-\u4e32\u884c-\u64cd\u4f5c",level:3},{value:"25.5 \u4f9d\u8d56\u6ce8\u5165\u4f7f\u7528",id:"255-\u4f9d\u8d56\u6ce8\u5165\u4f7f\u7528",level:2},{value:"25.6 \u5982\u4f55\u90e8\u7f72",id:"256-\u5982\u4f55\u90e8\u7f72",level:2},{value:"25.6.1 \u5171\u5bbf\u4e3b\u65b9\u5f0f",id:"2561-\u5171\u5bbf\u4e3b\u65b9\u5f0f",level:3},{value:"25.6.2 \u72ec\u7acb <code>Worker Service</code> \u65b9\u5f0f",id:"2562-\u72ec\u7acb-worker-service-\u65b9\u5f0f",level:3},{value:"\u90e8\u7f72\u5230 <code>Windows Service</code>",id:"\u90e8\u7f72\u5230-windows-service",level:4},{value:"\u90e8\u7f72\u5230 <code>Linux \u5b88\u62a4\u7a0b\u5e8f</code>",id:"\u90e8\u7f72\u5230-linux-\u5b88\u62a4\u7a0b\u5e8f",level:4},{value:"25.7 \u5173\u4e8e <code>Windows</code> \u90e8\u7f72\u65e5\u5fd7\u95ee\u9898",id:"257-\u5173\u4e8e-windows-\u90e8\u7f72\u65e5\u5fd7\u95ee\u9898",level:2},{value:"25.8 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"258-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function h(e){const r={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",mdxAdmonitionTitle:"mdxAdmonitionTitle",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.h2,{id:"251-\u5173\u4e8e\u8f85\u52a9\u89d2\u8272\u670d\u52a1",children:"25.1 \u5173\u4e8e\u8f85\u52a9\u89d2\u8272\u670d\u52a1"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:".NET Core 3.0"})," \u65b0\u589e\u4e86 ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u7684\u65b0\u9879\u76ee\u6a21\u677f\uff0c",(0,s.jsxs)(r.strong,{children:["\u53ef\u4ee5\u7f16\u5199\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u540e\u53f0\u670d\u52a1\uff0c\u5e76\u4e14\u80fd\u8f7b\u677e\u7684\u90e8\u7f72\u6210 ",(0,s.jsx)(r.code,{children:"Windows\u670d\u52a1"})," \u6216 ",(0,s.jsx)(r.code,{children:"Linux \u5b88\u62a4\u7a0b\u5e8f"})]}),"\u3002"]}),"\n",(0,s.jsx)(r.p,{children:"\u76ee\u524d\u5fae\u8f6f\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u521b\u5efa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u540e\u53f0\u670d\u52a1\uff1a"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.strong,{children:"\u5171\u5bbf\u4e3b\u65b9\u5f0f"}),"\uff1a\u4e2d\u5c0f\u578b\u9879\u76ee\u63a8\u8350\uff0c\u65e0\u9700\u5355\u72ec\u90e8\u7f72 ",(0,s.jsx)(r.code,{children:"Windows/Linux"})," \u670d\u52a1"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsxs)(r.strong,{children:["\u72ec\u7acb ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u65b9\u5f0f"]}),"\uff1a\u9700\u72ec\u7acb\u90e8\u7f72 ",(0,s.jsx)(r.code,{children:"Windows/Linux"})," \u670d\u52a1"]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"252-\u5171\u5bbf\u4e3b\u65b9\u5f0f",children:"25.2 \u5171\u5bbf\u4e3b\u65b9\u5f0f"}),"\n",(0,s.jsxs)(r.p,{children:["\u5171\u5bbf\u4e3b\u65b9\u5f0f\u6307\u7684\u662f\u5728\u73b0\u6709\u7684 ",(0,s.jsx)(r.code,{children:"Web"})," \u6216\u5176\u4ed6\u5e94\u7528\u7a0b\u4e2d\u521b\u5efa\u7c7b\u6587\u4ef6\u5e76\u6d3e\u751f\u81ea ",(0,s.jsx)(r.code,{children:"BackgroundService"})," \u7c7b\u5373\u53ef\u3002",(0,s.jsx)(r.strong,{children:"\u8fd9\u79cd\u65b9\u5f0f\u7684\u5178\u578b\u7279\u70b9\u5c31\u662f\u548c\u5e94\u7528\u5171\u751f\u5b58\u5468\u671f\uff0c\u5e94\u7528\u542f\u52a8\u65f6\u542f\u52a8\uff0c\u5e94\u7528\u7ed3\u675f\u505c\u6b62\u8fd0\u884c\u3002"})]}),"\n",(0,s.jsx)(r.admonition,{title:"\u63a8\u8350\u7b49\u7ea7",type:"tip",children:(0,s.jsx)(r.p,{children:"\u63a8\u8350\u4e2d\u5c0f\u578b\u9879\u76ee\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002"})}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {8,11,12-17}",children:"using Microsoft.Extensions.Hosting;\r\nusing System;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace YourPoject.Web.Core;\r\n\r\npublic class Worker : BackgroundService\r\n{\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n Console.WriteLine(DateTime.Now);\r\n\r\n // \u5ef6\u8fdf 1 \u79d2\r\n await Task.Delay(1000, stoppingToken);\r\n }\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(r.p,{children:["\u4e4b\u540e\u5728 ",(0,s.jsx)(r.code,{children:"Startup.cs"})," \u4e2d\u6ce8\u518c\u5373\u53ef\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"services.AddHostedService<Worker>();\n"})}),"\n",(0,s.jsx)(r.h3,{id:"2521-\u6700\u4f73\u5b9e\u8df5",children:"25.2.1 \u6700\u4f73\u5b9e\u8df5"}),"\n",(0,s.jsxs)(r.p,{children:["\u6700\u597d\u7684\u5b9e\u8df5\u65b9\u5f0f\u662f\u521b\u5efa\u72ec\u7acb\u7684\u7c7b\u5e93\u9879\u76ee\uff1a",(0,s.jsx)(r.code,{children:"YourProject.BackgroundServices"}),"\uff0c\u4e4b\u540e\u6dfb\u52a0 ",(0,s.jsx)(r.code,{children:"YourPoject.Application"})," \u548c ",(0,s.jsx)(r.code,{children:"YourPoject.Core"})," \u5c42\u5f15\u7528\uff0c\u5c06\u6240\u6709\u7684 ",(0,s.jsx)(r.code,{children:"Worker"})," \u653e\u5728\u8be5\u5c42\uff0c\u540c\u65f6\u521b\u5efa ",(0,s.jsx)(r.code,{children:"Startup.cs"})," \u7c7b\u8fdb\u884c ",(0,s.jsx)(r.code,{children:"Worker"})," \u7edf\u4e00\u6ce8\u518c\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {5,7,9-10}",children:"using Microsoft.Extensions.DependencyInjection;\r\n\r\nnamespace YourProject.BackgroundServices;\r\n\r\npublic sealed class Startup : AppStartup\r\n{\r\n public void ConfigureServices(IServiceCollection services)\r\n {\r\n services.AddHostedService<Worker>();\r\n services.AddHostedService<Worker2>();\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(r.h2,{id:"253-\u72ec\u7acb-worker-service-\u65b9\u5f0f",children:["25.3 \u72ec\u7acb ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u65b9\u5f0f"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsxs)(r.strong,{children:["\u72ec\u7acb ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u65b9\u5f0f\u7684\u4e3b\u8981\u7279\u70b9\u5c31\u662f\u5b83\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u9879\u76ee"]}),"\uff0c\u548c\u73b0\u6709\u7684\u9879\u76ee\u6ca1\u6709\u76f4\u63a5\u5173\u8054\u5173\u7cfb\uff0c",(0,s.jsx)(r.strong,{children:"\u9700\u8981\u5206\u5f00\u72ec\u7acb\u90e8\u7f72"}),"\u3002"]}),"\n",(0,s.jsx)(r.admonition,{title:"\u63a8\u8350\u7b49\u7ea7",type:"tip",children:(0,s.jsxs)(r.p,{children:["\u63a8\u8350\u4e2d\u5927\u578b\u9879\u76ee\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u72ec\u7acb\u90e8\u7f72\u6210 ",(0,s.jsx)(r.code,{children:"Windows Service"})," \u6216\u8005 ",(0,s.jsx)(r.code,{children:"Linux \u5b88\u62a4\u8fdb\u7a0b"}),"\uff0c\u5177\u6709\u72ec\u7acb\u751f\u5b58\u5468\u671f\uff0c\u5373\u4f7f\u5e94\u7528\u6545\u969c\u4e86\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u5b83\u7684\u8fd0\u884c\u3002"]})}),"\n",(0,s.jsxs)(r.h3,{id:"2531-\u5982\u4f55\u521b\u5efa-worker-service",children:["25.3.1 \u5982\u4f55\u521b\u5efa ",(0,s.jsx)(r.code,{children:"Worker Service"})]}),"\n",(0,s.jsxs)(r.p,{children:["\u901a\u8fc7 ",(0,s.jsx)(r.code,{children:"Visual Studio 2019"})," \u63d0\u4f9b\u7684 ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u53ef\u76f4\u63a5\u521b\u5efa\u3002\u5982\u56fe\uff1a"]}),"\n",(0,s.jsx)("img",{src:(0,o.Z)("img/wk.png")}),"\n",(0,s.jsxs)(r.h3,{id:"2532-\u521b\u5efa-worker",children:["25.3.2 \u521b\u5efa ",(0,s.jsx)(r.code,{children:"Worker"})]}),"\n",(0,s.jsxs)(r.p,{children:["\u5f53\u6211\u4eec\u521b\u5efa\u597d ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u9879\u76ee\u65f6\uff0c\u5df2\u7ecf\u81ea\u5e26\u4e86\u4e00\u4e2a ",(0,s.jsx)(r.code,{children:"Worker"})," \u7c7b\u5e76\u7ee7\u627f\u81ea ",(0,s.jsx)(r.code,{children:"BackgroundService"})," \u57fa\u7c7b\u3002"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker"})," \u6b63\u662f\u6211\u4eec\u8f85\u52a9\u89d2\u8272\u7684\u4e3b\u8981\u5de5\u4f5c\u7c7b\uff0c\u5728\u8fd9\u91cc\u6211\u4eec\u7f16\u5199\u6211\u4eec\u6240\u6709\u7684\u4e1a\u52a1\u903b\u8f91\u3002\u901a\u5e38 ",(0,s.jsx)(r.code,{children:"Worker"})," \u9ed8\u8ba4\u683c\u5f0f\u4e3a\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {9,18}",children:'using Microsoft.Extensions.Hosting;\r\nusing Microsoft.Extensions.Logging;\r\nusing System;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Worker : BackgroundService\r\n {\r\n private readonly ILogger<Worker> _logger;\r\n\r\n public Worker(ILogger<Worker> logger)\r\n {\r\n _logger = logger;\r\n }\r\n\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n _logger.LogInformation("Worker running at: {time}", DateTime.Now);\r\n await Task.Delay(1000, stoppingToken);\r\n }\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsxs)(r.strong,{children:["\u5f53\u6211\u4eec\u521b\u5efa\u4e86 ",(0,s.jsx)(r.code,{children:"Worker"})," \u7c7b\u4e4b\u540e\uff0c\u9700\u8981\u5728 ",(0,s.jsx)(r.code,{children:"Program.cs"})," \u4e2d\u8fdb\u884c\u6ce8\u518c"]}),"\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {17}",children:"using Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Program\r\n {\r\n public static void Main(string[] args)\r\n {\r\n CreateHostBuilder(args).Build().Run();\r\n }\r\n\r\n public static IHostBuilder CreateHostBuilder(string[] args) =>\r\n Host.CreateDefaultBuilder(args)\r\n .ConfigureServices((hostContext, services) =>\r\n {\r\n services.AddHostedService<Worker>();\r\n });\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"important",children:(0,s.jsxs)(r.p,{children:["\u5982\u679c\u4f7f\u7528\u4e86 ",(0,s.jsx)(r.code,{children:"Furion"})," \u5305\u540e\u53ef\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c\uff0c",(0,s.jsxs)(r.strong,{children:["\u8bf7\u540c\u65f6\u786e\u4fdd ",(0,s.jsx)(r.code,{children:"Worker"})," \u58f0\u660e\u4e3a ",(0,s.jsx)(r.code,{children:"public"})," \u7ea7\u522b\u3002"]})]})}),"\n",(0,s.jsxs)(r.h3,{id:"2533-\u591a\u4e2a-worker",children:["25.3.3 \u591a\u4e2a ",(0,s.jsx)(r.code,{children:"Worker"})]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u662f\u652f\u6301\u5b9a\u4e49\u591a\u4e2a ",(0,s.jsx)(r.code,{children:"Worker"})," \u8fdb\u884c\u534f\u8c03\u5de5\u4f5c\u7684\uff0c\u6bcf\u4e2a ",(0,s.jsx)(r.code,{children:"Worker"})," \u662f\u5b8c\u5168\u72ec\u7acb\u7684\u5de5\u4f5c\u73af\u5883\uff0c\u4f46\u53ef\u5171\u4eab\u540c\u4e00\u4e3b\u8fdb\u7a0b\u4fe1\u606f\u3002"]}),"\n",(0,s.jsx)(r.h3,{id:"2534-\u751f\u547d\u5468\u671f",children:"25.3.4 \u751f\u547d\u5468\u671f"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u4e3a ",(0,s.jsx)(r.code,{children:"Worker"})," \u63d0\u4f9b\u4e86\u4e09\u4e2a\u6267\u884c\u65b9\u6cd5\uff0c\u5206\u522b\u4ee3\u8868\u4e09\u4e2a\u751f\u547d\u5468\u671f\uff1a"]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"StartAsync"}),"\uff1a\u8d1f\u8d23\u542f\u52a8 ",(0,s.jsx)(r.code,{children:"Worker Service"}),"\uff0c\u5982\u679c\u8c03\u7528 ",(0,s.jsx)(r.code,{children:"StartAsync"})," \u65b9\u6cd5\u7684\u7ebf\u7a0b\u88ab\u4e00\u76f4\u963b\u585e\u4e86\uff0c\u90a3\u4e48 ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u7684\u542f\u52a8\u5c31\u4e00\u76f4\u5b8c\u6210\u4e0d\u4e86"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"ExecuteAsync"}),"\uff1a",(0,s.jsx)(r.code,{children:"Worker Service"})," \u771f\u6b63\u5b9e\u73b0\u4e1a\u52a1\u903b\u8f91\u7684\u5730\u65b9\uff0c\u8fd9\u91cc\u4e0d\u80fd\u8c03\u7528\u963b\u585e\u4ee3\u7801\uff01\uff01\uff01"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"StopAsync"}),"\uff1a\u8d1f\u8d23\u7ed3\u675f ",(0,s.jsx)(r.code,{children:"Worker Service"}),"\uff0c\u5982\u679c\u8c03\u7528 ",(0,s.jsx)(r.code,{children:"StopAsync"})," \u65b9\u6cd5\u7684\u7ebf\u7a0b\u88ab\u4e00\u76f4\u963b\u585e\u4e86\uff0c\u90a3\u4e48 ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u7684\u7ed3\u675f\u5c31\u4e00\u76f4\u5b8c\u6210\u4e0d\u4e86"]}),"\n"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {19,25,35}",children:'using Microsoft.Extensions.Hosting;\r\nusing Microsoft.Extensions.Logging;\r\nusing System;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Worker : BackgroundService\r\n {\r\n private readonly ILogger<Worker> _logger;\r\n\r\n public Worker(ILogger<Worker> logger)\r\n {\r\n _logger = logger;\r\n }\r\n\r\n // \u542f\u52a8\r\n public override Task StartAsync(CancellationToken cancellationToken)\r\n {\r\n return base.StartAsync(cancellationToken);\r\n }\r\n\r\n // \u6267\u884c\u903b\u8f91\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n _logger.LogInformation("Worker running at: {time}", DateTime.Now);\r\n await Task.Delay(1000, stoppingToken);\r\n }\r\n }\r\n\r\n // \u505c\u6b62\r\n public override Task StopAsync(CancellationToken cancellationToken)\r\n {\r\n return base.StopAsync(cancellationToken);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(r.h3,{id:"2535-\u96c6\u6210-furion",children:["25.3.5 \u96c6\u6210 ",(0,s.jsx)(r.code,{children:"Furion"})]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u96c6\u6210 ",(0,s.jsx)(r.code,{children:"Furion"})," \u975e\u5e38\u65b9\u4fbf\uff0c\u53ea\u9700\u8981\u5b89\u88c5 ",(0,s.jsx)(r.code,{children:"Furion"})," \u7684\u5305\u5373\u53ef\uff0c\u5e76\u5728 ",(0,s.jsx)(r.code,{children:"Program.cs"})," \u4e2d\u8c03\u7528 ",(0,s.jsx)(r.code,{children:".Inject()"})," \u65b9\u6cd5\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {15}",children:"using Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Program\r\n {\r\n public static void Main(string[] args)\r\n {\r\n CreateHostBuilder(args).Build().Run();\r\n }\r\n\r\n public static IHostBuilder CreateHostBuilder(string[] args) =>\r\n Host.CreateDefaultBuilder(args)\r\n .Inject()\r\n .ConfigureServices((hostContext, services) =>\r\n {\r\n // \u4ee5\u4e0b\u4ee3\u7801\u53ef\u4e0d\u7528\u7f16\u5199\uff0cFurion \u5df2\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c Worker;\r\n // services.AddHostedService<Worker>();\r\n });\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(r.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c",(0,s.jsx)(r.code,{children:"Inject()"})," \u65b9\u6cd5\u6ce8\u518c\u4e86 ",(0,s.jsx)(r.code,{children:"\u65e5\u5fd7\u3001\u7f13\u5b58\u3001\u4f9d\u8d56\u6ce8\u5165\u3001\u52a0\u8f7d\u914d\u7f6e\u3001\u81ea\u5b9a\u4e49 Startup"})," \u529f\u80fd\u3002"]}),"\n",(0,s.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,s.jsxs)(r.p,{children:["\u96c6\u6210 ",(0,s.jsx)(r.code,{children:"Furion"})," \u540e\u4f1a\u81ea\u52a8\u626b\u63cf ",(0,s.jsx)(r.code,{children:"Worker"})," \u7c7b\u5e76\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c\u3002"]})}),"\n",(0,s.jsx)(r.h3,{id:"2536-\u6ce8\u518c\u670d\u52a1",children:"25.3.6 \u6ce8\u518c\u670d\u52a1"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u6ce8\u518c\u670d\u52a1\u548c ",(0,s.jsx)(r.code,{children:"Web"})," \u7565\u6709\u4e0d\u540c\uff0c",(0,s.jsx)(r.code,{children:"Web"})," \u4e3b\u8981\u5728 ",(0,s.jsx)(r.code,{children:"Starup.cs"})," \u7c7b\u4e2d\u6ce8\u518c\uff0c",(0,s.jsx)(r.code,{children:"Worker Service"})," \u5728 ",(0,s.jsx)(r.code,{children:"Program.cs"})," \u542f\u52a8\u7c7b\u7684 ",(0,s.jsx)(r.code,{children:"ConfigureServices"})," \u65b9\u6cd5\u4e2d\u6ce8\u518c\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {16-28}",children:"using Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Program\r\n {\r\n public static void Main(string[] args)\r\n {\r\n CreateHostBuilder(args).Build().Run();\r\n }\r\n\r\n public static IHostBuilder CreateHostBuilder(string[] args) =>\r\n Host.CreateDefaultBuilder(args)\r\n .Inject()\r\n .ConfigureServices((hostContext, services) =>\r\n {\r\n // \u6ce8\u518c\u6570\u636e\u5e93\u670d\u52a1\r\n services.AddDatabaseAccessor(options =>\r\n {\r\n options.AddDb<DefaultDbContext>();\r\n });\r\n\r\n // \u6ce8\u518c\u8fdc\u7a0b\u8bf7\u6c42\r\n services.AddRemoteRequest();\r\n\r\n // \u7b49\u7b49\u5176\u4ed6\u670d\u52a1\u6ce8\u518c\r\n });\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(r.h2,{id:"254-\u5b9e\u73b0\u7b80\u5355\u5b9a\u65f6\u4efb\u52a1",children:"25.4 \u5b9e\u73b0\u7b80\u5355\u5b9a\u65f6\u4efb\u52a1"}),"\n",(0,s.jsx)(r.admonition,{title:"\u5c0f\u5efa\u8bae",type:"tip",children:(0,s.jsx)(r.p,{children:(0,s.jsxs)(r.strong,{children:["\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528 \u3010",(0,s.jsx)(r.a,{href:"/docs/job",children:"26.1 \u8c03\u5ea6\u4f5c\u4e1a"}),"\u3011 \u7ae0\u8282\u5185\u5bb9\u5b9e\u73b0\u5f3a\u5927\u7684\u5206\u5e03\u5f0f\u5b9a\u65f6\u4efb\u52a1\u3002"]})})}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Furion"})," \u6846\u67b6\u4e3a ",(0,s.jsx)(r.code,{children:"BackgroundService"})," \u63d0\u4f9b\u4e86\u5b9a\u65f6\u4efb\u52a1\u7684\u652f\u6301\u3002"]}),"\n",(0,s.jsx)(r.h3,{id:"2541-\u95f4\u9694\u6267\u884c\u65b9\u5f0f",children:"25.4.1 \u95f4\u9694\u6267\u884c\u65b9\u5f0f"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {7,18,20-29}",children:'namespace WorkerService;\r\n\r\npublic class Worker : BackgroundService\r\n{\r\n private readonly ILogger<Worker> _logger;\r\n\r\n private const int delay = 1000;\r\n\r\n public Worker(ILogger<Worker> logger)\r\n {\r\n _logger = logger;\r\n }\r\n\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n await Task.Delay(delay, stoppingToken);\r\n\r\n var taskFactory = new TaskFactory(System.Threading.Tasks.TaskScheduler.Current);\r\n await taskFactory.StartNew(async () =>\r\n {\r\n // \u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u5199\u5230\u8fd9\u91cc\u9762\r\n\r\n _logger.LogInformation("Worker running at: {time}", DateTime.Now);\r\n\r\n await Task.CompletedTask;\r\n\r\n }, stoppingToken);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(r.h3,{id:"2542-cron-\u8868\u8fbe\u5f0f\u6267\u884c\u65b9\u5f0f",children:["25.4.2 ",(0,s.jsx)(r.code,{children:"Cron"})," \u8868\u8fbe\u5f0f\u6267\u884c\u65b9\u5f0f"]}),"\n",(0,s.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,s.jsxs)(r.p,{children:["\u5982\u9700\u4e86\u89e3 ",(0,s.jsx)(r.code,{children:"Cron"})," \u8868\u8fbe\u5f0f\u5185\u5bb9\uff0c\u53ef\u67e5\u9605 \u3010",(0,s.jsx)(r.a,{href:"/docs/cron",children:"26.2 Cron \u8868\u8fbe\u5f0f"}),"\u3011 \u7ae0\u8282\u5185\u5bb9\u3002"]})}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {9,14,21,23-31}",children:'using Furion.TimeCrontab;\r\n\r\nnamespace WorkerService;\r\n\r\npublic class Worker : BackgroundService\r\n{\r\n private readonly ILogger<Worker> _logger;\r\n\r\n private readonly Crontab _crontab;\r\n\r\n public Worker(ILogger<Worker> logger)\r\n {\r\n _logger = logger;\r\n _crontab = Crontab.Parse("* * * * * *", CronStringFormat.WithSeconds);\r\n }\r\n\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n await Task.Delay(_crontab.GetSleepTimeSpan(DateTime.Now), stoppingToken);\r\n\r\n var taskFactory = new TaskFactory(System.Threading.Tasks.TaskScheduler.Current);\r\n await taskFactory.StartNew(async () =>\r\n {\r\n // \u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u5199\u5230\u8fd9\u91cc\u9762\r\n\r\n _logger.LogInformation("Worker running at: {time}", DateTime.Now);\r\n\r\n await Task.CompletedTask;\r\n }, stoppingToken);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(r.admonition,{type:"caution",children:[(0,s.jsxs)(r.mdxAdmonitionTitle,{children:[(0,s.jsx)(r.code,{children:"BackgroundService"})," \u65b9\u5f0f\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u6ce8\u610f\u4e8b\u9879"]}),(0,s.jsxs)(r.p,{children:["\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ea\u662f\u7b80\u5355\u7684\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\uff0c\u4f46~~",(0,s.jsx)(r.strong,{children:"\u4e0d\u80fd\u5bf9\u7ebf\u7a0b\u548c\u65f6\u95f4\u8fdb\u884c\u7cbe\u51c6\u63a7\u5236\uff0c\u53ef\u80fd\u5b58\u5728\u4e00\u4e9b\u4e0d\u6267\u884c\u6216\u8005\u91cd\u590d\u6267\u884c\u7b49\u95ee\u9898"}),"~~\u3002"]}),(0,s.jsx)(r.p,{children:(0,s.jsxs)(r.strong,{children:["\u6240\u4ee5\uff0c\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528 \u3010",(0,s.jsx)(r.a,{href:"/docs/job",children:"26.1 \u8c03\u5ea6\u4f5c\u4e1a"}),"\u3011 \u7ae0\u8282\u5185\u5bb9\u5b9e\u73b0\u5f3a\u5927\u7684\u5206\u5e03\u5f0f\u5b9a\u65f6\u4efb\u52a1\u3002"]})})]}),"\n",(0,s.jsxs)(r.h3,{id:"2543-\u5b9e\u73b0-\u4e32\u884c-\u64cd\u4f5c",children:["25.4.3 \u5b9e\u73b0 ",(0,s.jsx)(r.code,{children:"\u4e32\u884c"})," \u64cd\u4f5c"]}),"\n",(0,s.jsxs)(r.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b9a\u65f6\u4efb\u52a1\u90fd\u662f\u91c7\u7528 ",(0,s.jsx)(r.code,{children:"\u5e76\u884c"})," \u7684\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1a\u7b49\u5f85\u4e0a\u4e00\u6b21\u4efb\u52a1\u5b8c\u6210\uff0c\u5982\u679c\u9700\u8981\u7b49\u5f85\u4e0a\u4e00\u6b21\u4efb\u52a1\u5b8c\u6210\uff0c\u53ef\u4ee5\u4fee\u6539\u4e3a ",(0,s.jsx)(r.code,{children:"\u4e32\u884c"})," \u65b9\u5f0f\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {11,23-24,30,37-38,40}",children:'using Furion.TimeCrontab;\r\n\r\nnamespace WorkerService;\r\n\r\npublic class Worker : BackgroundService\r\n{\r\n private readonly ILogger<Worker> _logger;\r\n\r\n private readonly Crontab _crontab;\r\n\r\n private bool _isLock = false;\r\n\r\n public Worker(ILogger<Worker> logger)\r\n {\r\n _logger = logger;\r\n _crontab = Crontab.Parse("* * * * * *", CronStringFormat.WithSeconds);\r\n }\r\n\r\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n if (_isLock) goto next;\r\n _isLock = true;\r\n\r\n var taskFactory = new TaskFactory(System.Threading.Tasks.TaskScheduler.Current);\r\n var task = await taskFactory.StartNew(async () =>\r\n {\r\n // \u6a21\u62df\u8017\u65f6\u64cd\u4f5c\r\n await Task.Delay(2000);\r\n\r\n _logger.LogInformation("Worker running at: {time}", DateTime.Now);\r\n\r\n await Task.CompletedTask;\r\n }, stoppingToken);\r\n\r\n // \u7b49\u5f85\u4efb\u52a1\u5b8c\u6210\r\n await task.ContinueWith(task => _isLock = false);\r\n\r\n next:\r\n await Task.Delay(_crontab.GetSleepTimeSpan(DateTime.Now), stoppingToken);\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(r.h2,{id:"255-\u4f9d\u8d56\u6ce8\u5165\u4f7f\u7528",children:"25.5 \u4f9d\u8d56\u6ce8\u5165\u4f7f\u7528"}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u53ea\u4e3a ",(0,s.jsx)(r.code,{children:"Worker"})," \u63d0\u4f9b\u4e86",(0,s.jsx)(r.strong,{children:"\u5355\u4f8b\u4f5c\u7528\u57df"}),"\u7684\u670d\u52a1\u6ce8\u5165\uff0c\u5982\u679c\u9700\u8981\u6ce8\u5165\u77ac\u65f6\u6216\u4f5c\u7528\u57df\u5bf9\u8c61\uff0c\u9700\u624b\u52a8\u521b\u5efa\u4f5c\u7528\u57df\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {7-8,18-19,24-25,28-32}",children:"public class Worker : BackgroundService\r\n{\r\n // \u65e5\u5fd7\u5bf9\u8c61\r\n private readonly ILogger<JobService> _logger;\r\n\r\n // \u670d\u52a1\u5de5\u5382\r\n private readonly IServiceScopeFactory _scopeFactory;\r\n public Worker(ILogger<Worker> logger\r\n , IServiceScopeFactory scopeFactory)\r\n {\r\n _logger = logger;\r\n _scopeFactory = scopeFactory;\r\n }\r\n\r\n protected override Task ExecuteAsync(CancellationToken stoppingToken)\r\n {\r\n // \u653e\u5728\u5faa\u73af\u5916\u53ef\u4ee5\u907f\u514d\u9ad8\u9891\u4e0b\u9891\u7e41\u521b\u5efa\u4f5c\u7528\u57df\u548c\u89e3\u6790\u670d\u52a1\r\n using var scope = _scopeFactory.CreateScope();\r\n var services = scope.ServiceProvider;\r\n\r\n while (!stoppingToken.IsCancellationRequested)\r\n {\r\n // \u653e\u5728\u5faa\u73af\u5185\u9488\u5bf9\u9891\u7387\u4e0d\u662f\u5f88\u9ad8\u7684\u64cd\u4f5c\r\n // using var scope = _scopeFactory.CreateScope();\r\n // var services = scope.ServiceProvider;\r\n\r\n // \u83b7\u53d6\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\r\n var dbContext = Db.GetDbContext(services);\r\n // \u83b7\u53d6\u4ed3\u50a8\r\n var respository = Db.GetRepository<Person>(services);\r\n // \u89e3\u6790\u5176\u4ed6\u670d\u52a1\r\n var otherService = services.GetService<XXX>();\r\n }\r\n\r\n return Task.CompletedTask;\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(r.h2,{id:"256-\u5982\u4f55\u90e8\u7f72",children:"25.6 \u5982\u4f55\u90e8\u7f72"}),"\n",(0,s.jsx)(r.h3,{id:"2561-\u5171\u5bbf\u4e3b\u65b9\u5f0f",children:"25.6.1 \u5171\u5bbf\u4e3b\u65b9\u5f0f"}),"\n",(0,s.jsxs)(r.p,{children:["\u5171\u5bbf\u4e3b\u65b9\u5f0f\u65b9\u5f0f\u90e8\u7f72\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u90e8\u7f72\u6240\u5728\u7684 ",(0,s.jsx)(r.code,{children:"Web"})," \u6216\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u9879\u76ee\u5373\u53ef\uff0c\u4f1a\u81ea\u52a8\u968f\u7740\u9879\u76ee\u542f\u52a8\u81ea\u52a8\u542f\u52a8\u3002"]}),"\n",(0,s.jsx)(r.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:(0,s.jsxs)(r.p,{children:["\u5982\u679c\u90e8\u7f72\u5230 ",(0,s.jsx)(r.code,{children:"IIS"})," \u4e2d\uff0c\u53ef\u80fd\u5b58\u5728 ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u88ab\u56de\u6536\u7684\u60c5\u51b5\uff0c\u6bd5\u7adf\u662f\u548c\u7f51\u7ad9\u540c\u4e00\u4e2a\u5bbf\u4e3b\u3002"]})}),"\n",(0,s.jsxs)(r.h3,{id:"2562-\u72ec\u7acb-worker-service-\u65b9\u5f0f",children:["25.6.2 \u72ec\u7acb ",(0,s.jsx)(r.code,{children:"Worker Service"})," \u65b9\u5f0f"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Worker Service"})," \u652f\u6301\u90e8\u7f72\u5230 ",(0,s.jsx)(r.code,{children:"Windows Service"})," \u4e2d \u6216 ",(0,s.jsx)(r.code,{children:"Linux \u5b88\u62a4\u8fdb\u7a0b\u4e2d"})]}),"\n",(0,s.jsx)(r.hr,{}),"\n",(0,s.jsxs)(r.h4,{id:"\u90e8\u7f72\u5230-windows-service",children:["\u90e8\u7f72\u5230 ",(0,s.jsx)(r.code,{children:"Windows Service"})]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u4e00\u6b65"}),"\uff1a\u5b89\u88c5 ",(0,s.jsx)(r.code,{children:"Microsoft.Extensions.Hosting.WindowsServices"})," \u62d3\u5c55\u5305"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u4e8c\u6b65"}),"\uff1a\u5728 ",(0,s.jsx)(r.code,{children:"Program.cs"})," \u4e2d\u6dfb\u52a0 ",(0,s.jsx)(r.code,{children:".UseWindowsService()"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {15}",children:"using Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Program\r\n {\r\n public static void Main(string[] args)\r\n {\r\n CreateHostBuilder(args).Build().Run();\r\n }\r\n\r\n public static IHostBuilder CreateHostBuilder(string[] args) =>\r\n Host.CreateDefaultBuilder(args)\r\n .UseWindowsService()\r\n .Inject()\r\n .ConfigureServices((hostContext, services) =>\r\n {\r\n // \u4ee5\u4e0b\u4ee3\u7801\u53ef\u4e0d\u7528\u7f16\u5199\uff0cFurion \u5df2\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c Worker;\r\n // services.AddHostedService<Worker>();\r\n });\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u4e09\u6b65"}),"\uff1a\u53d1\u5e03 ",(0,s.jsx)(r.code,{children:"Worker Service"}),"\uff0c\u53ef\u901a\u8fc7 ",(0,s.jsx)(r.code,{children:"dotnet publish -c Release -o C:\\FurionWorker"})," \u547d\u4ee4\u53d1\u5e03\u6216\u901a\u8fc7 ",(0,s.jsx)(r.code,{children:"Visual Studio 2019"})," \u53d1\u5e03\u3002"]}),"\n"]}),"\n",(0,s.jsxs)(r.p,{children:["\u72ec\u7acb\u53d1\u5e03\u4e0d\u4f9d\u8d56 SDK \u65b9\u5f0f ",(0,s.jsx)(r.code,{children:"dotnet publish -c release -r win10-x64 --framework net6.0"})]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u56db\u6b65"}),"\uff1a\u901a\u8fc7 ",(0,s.jsx)(r.code,{children:"sc.exe"})," \u5de5\u5177\u6765\u7ba1\u7406\u5e76\u521b\u5efa ",(0,s.jsx)(r.code,{children:"Windows"})," \u670d\u52a1\uff0c\u901a\u8fc7 ",(0,s.jsx)(r.strong,{children:"\u7ba1\u7406\u5458\u6a21\u5f0f"})," \u5e76\u6253\u5f00\u63a7\u5236\u53f0\uff0c\u8f93\u5165\uff1a"]}),"\n"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cmd",children:"sc.exe create FurionWorkerServices binPath= C:\\FurionWorker\\FurionWorker.exe\n"})}),"\n",(0,s.jsxs)(r.p,{children:["\u6ce8\u610f",(0,s.jsx)(r.code,{children:"="}),"\u540e\u9762\u8981\u6709\u4e00\u4e2a\u7a7a\u683c\r\n\u521b\u5efa\u6210\u529f\u540e\u53ef\u901a\u8fc7 ",(0,s.jsx)(r.code,{children:"sc.exe query FurionWorkerServices"})," \u67e5\u770b\u670d\u52a1\u72b6\u6001\u3002"]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:(0,s.jsx)(r.strong,{children:"\u7b2c\u4e94\u6b65"})}),"\n"]}),"\n",(0,s.jsxs)(r.p,{children:["\u542f\u52a8\u670d\u52a1\uff1a",(0,s.jsx)(r.code,{children:"sc.exe start FurionWorkerServices"}),"\uff0c\u542f\u52a8\u4e4b\u540e\u5c31\u53ef\u4ee5\u5728 ",(0,s.jsx)(r.code,{children:"Windows"})," \u670d\u52a1\u5de5\u5177\u4e2d\u67e5\u770b\u4e86\u3002"]}),"\n",(0,s.jsxs)(r.p,{children:["\u505c\u6b62\u670d\u52a1\uff1a",(0,s.jsx)(r.code,{children:"sc.exe stop NETCoreDemoWorkerService"})]}),"\n",(0,s.jsxs)(r.p,{children:["\u5220\u9664\u670d\u52a1\uff1a",(0,s.jsx)(r.code,{children:"sc.exe delete NETCoreDemoWorkerService"})]}),"\n",(0,s.jsx)(r.admonition,{title:"\u7279\u522b\u63d0\u9192",type:"important",children:(0,s.jsxs)(r.p,{children:["\u4ee5\u4e0a\u6240\u6709 ",(0,s.jsx)(r.code,{children:"sc.exe"})," \u547d\u4ee4\u5fc5\u987b\u5728 ",(0,s.jsx)(r.strong,{children:"\u7ba1\u7406\u5458"})," \u6a21\u5f0f\u4e0b\u8fdb\u884c\u3002\r\nsc.exe delete NETCoreDemoWorkerService, \u6267\u884c\u5220\u9664\u65f6\u5019, \u628a",(0,s.jsx)(r.code,{children:"Windows"})," \u670d\u52a1\u5de5\u5177\u5173\u95ed, \u5426\u5219, \u7535\u8111\u91cd\u542f\u540e\u624d\u4f1a\u663e\u793a\u5220\u9664;"]})}),"\n",(0,s.jsx)(r.hr,{}),"\n",(0,s.jsxs)(r.h4,{id:"\u90e8\u7f72\u5230-linux-\u5b88\u62a4\u7a0b\u5e8f",children:["\u90e8\u7f72\u5230 ",(0,s.jsx)(r.code,{children:"Linux \u5b88\u62a4\u7a0b\u5e8f"})]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u4e00\u6b65"}),"\uff1a\u5b89\u88c5 ",(0,s.jsx)(r.code,{children:"Microsoft.Extensions.Hosting.Systemd"})," \u62d3\u5c55\u5305"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:"\u7b2c\u4e8c\u6b65"}),"\uff1a\u5728 ",(0,s.jsx)(r.code,{children:"Program.cs"})," \u4e2d\u6dfb\u52a0 ",(0,s.jsx)(r.code,{children:".UseSystemd()"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {15}",children:"using Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Hosting;\r\n\r\nnamespace FurionWorkers\r\n{\r\n public class Program\r\n {\r\n public static void Main(string[] args)\r\n {\r\n CreateHostBuilder(args).Build().Run();\r\n }\r\n\r\n public static IHostBuilder CreateHostBuilder(string[] args) =>\r\n Host.CreateDefaultBuilder(args)\r\n .UseSystemd()\r\n .Inject()\r\n .ConfigureServices((hostContext, services) =>\r\n {\r\n // \u4ee5\u4e0b\u4ee3\u7801\u53ef\u4e0d\u7528\u7f16\u5199\uff0cFurion \u5df2\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c Worker;\r\n // services.AddHostedService<Worker>();\r\n });\r\n }\r\n}\n"})}),"\n",(0,s.jsxs)(r.p,{children:["\u90e8\u7f72\u5230 ",(0,s.jsx)(r.code,{children:"Linux \u5b88\u62a4\u8fdb\u7a0b"})," \u5c31\u662f\u8fd9\u4e48\u7b80\u5355\u3002"]}),"\n",(0,s.jsxs)(r.h2,{id:"257-\u5173\u4e8e-windows-\u90e8\u7f72\u65e5\u5fd7\u95ee\u9898",children:["25.7 \u5173\u4e8e ",(0,s.jsx)(r.code,{children:"Windows"})," \u90e8\u7f72\u65e5\u5fd7\u95ee\u9898"]}),"\n",(0,s.jsxs)(r.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 ",(0,s.jsx)(r.code,{children:"Windows Services"})," \u90e8\u7f72\u540e\uff0c\u65e5\u5fd7\u6587\u4ef6\u53ef\u80fd\u4f1a\u5728\u7cfb\u7edf\u76d8\u7684 ",(0,s.jsx)(r.code,{children:"System32"})," \u4e0b\u3002"]}),"\n",(0,s.jsx)("img",{src:(0,o.Z)("img/rjs.jpg")}),"\n",(0,s.jsx)(r.h2,{id:"258-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"25.8 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,s.jsx)(r.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,s.jsxs)(r.p,{children:["\u7ed9 Furion \u63d0 ",(0,s.jsx)(r.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function x(e={}){const{wrapper:r}={...(0,i.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>d,a:()=>c});var s=n(7294);const i={},o=s.createContext(i);function c(e){const r=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function d(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),s.createElement(o.Provider,{value:r},e.children)}}}]);