You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.5 KiB
JavaScript
1 line
7.5 KiB
JavaScript
"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[223],{3101:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>t,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>c,toc:()=>l});var i=r(5893),s=r(1151);const a={id:"sparetime",title:"12. SpareTime \u9759\u6001\u7c7b",sidebar_label:"12. SpareTime \u9759\u6001\u7c7b"},o=void 0,c={id:"global/sparetime",title:"12. SpareTime \u9759\u6001\u7c7b",description:"\u4ee5\u4e0b\u5185\u5bb9\u5728 Furion 4.8.4 + \u7248\u672c\u4e2d\u5df2\u79fb\u9664\u3002",source:"@site/docs/global/sparetime.mdx",sourceDirName:"global",slug:"/global/sparetime",permalink:"/docs/global/sparetime",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/global/sparetime.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1673022799,formattedLastUpdatedAt:"Jan 6, 2023",frontMatter:{id:"sparetime",title:"12. SpareTime \u9759\u6001\u7c7b",sidebar_label:"12. SpareTime \u9759\u6001\u7c7b"},sidebar:"global",previous:{title:"11. Scoped \u9759\u6001\u7c7b",permalink:"/docs/global/scoped"},next:{title:"13. FS \u9759\u6001\u7c7b",permalink:"/docs/global/fs"}},t={},l=[{value:"12.1 \u521d\u59cb\u5316\u4efb\u52a1",id:"121-\u521d\u59cb\u5316\u4efb\u52a1",level:2},{value:"12.2 \u5b9e\u73b0\u540e\u53f0\u6267\u884c",id:"122-\u5b9e\u73b0\u540e\u53f0\u6267\u884c",level:2},{value:"12.3 \u5f00\u59cb\u4e00\u4e2a\u4efb\u52a1",id:"123-\u5f00\u59cb\u4e00\u4e2a\u4efb\u52a1",level:2},{value:"12.4 \u6682\u505c\u4e00\u4e2a\u4efb\u52a1",id:"124-\u6682\u505c\u4e00\u4e2a\u4efb\u52a1",level:2},{value:"12.5 \u53d6\u6d88\u4e00\u4e2a\u4efb\u52a1",id:"125-\u53d6\u6d88\u4e00\u4e2a\u4efb\u52a1",level:2},{value:"12.6 \u9500\u6bc1\u6240\u6709\u4efb\u52a1",id:"126-\u9500\u6bc1\u6240\u6709\u4efb\u52a1",level:2},{value:"12.7 \u83b7\u53d6\u6240\u6709\u4efb\u52a1",id:"127-\u83b7\u53d6\u6240\u6709\u4efb\u52a1",level:2},{value:"12.8 \u83b7\u53d6\u5355\u4e2a\u4efb\u52a1",id:"128-\u83b7\u53d6\u5355\u4e2a\u4efb\u52a1",level:2},{value:"12.9 \u89e3\u6790 <code>Cron</code> \u8868\u8fbe\u5f0f",id:"129-\u89e3\u6790-cron-\u8868\u8fbe\u5f0f",level:2},{value:"12.10 <code>BackgroundService</code> \u95f4\u9694\u5b9a\u65f6\u4efb\u52a1",id:"1210-backgroundservice-\u95f4\u9694\u5b9a\u65f6\u4efb\u52a1",level:2},{value:"12.11 <code>BackgroundService</code> <code>Cron</code> \u5b9a\u65f6\u4efb\u52a1",id:"1211-backgroundservice-cron-\u5b9a\u65f6\u4efb\u52a1",level:2}];function d(e){const n={admonition:"admonition",code:"code",h2:"h2",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{title:"\u91cd\u8981\u58f0\u660e",type:"warning",children:(0,i.jsxs)(n.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u5728 ",(0,i.jsx)(n.code,{children:"Furion 4.8.4 +"})," \u7248\u672c\u4e2d\u5df2\u79fb\u9664\u3002"]})}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"SpareTime"})," \u9759\u6001\u7c7b\u63d0\u4f9b\u4e86\u4e00\u4e9b\u65b9\u6cd5\u65b9\u4fbf\u521d\u59cb\u5316\u548c\u7ba1\u7406\u4efb\u52a1"]}),"\n",(0,i.jsx)(n.h2,{id:"121-\u521d\u59cb\u5316\u4efb\u52a1",children:"12.1 \u521d\u59cb\u5316\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u5f00\u542f\u95f4\u9694\u4efb\u52a1\r\nSpareTime.Do(interval, [options]);\r\n\r\n// \u5f00\u542f Cron \u8868\u8fbe\u5f0f\u4efb\u52a1\r\nSpareTime.Do(expression, [options]);\r\n\r\n// \u53ea\u6267\u884c\u4e00\u6b21\u4efb\u52a1\r\nSpareTime.DoOnce(interval, [options]);\r\n\r\n// \u5b9e\u73b0\u81ea\u5b9a\u4e49\u4efb\u52a1\r\nSpareTime.Do(()=>{\r\n return DateTime.Now.AddMinutes(10);\r\n},[options]);\n"})}),"\n",(0,i.jsx)(n.h2,{id:"122-\u5b9e\u73b0\u540e\u53f0\u6267\u884c",children:"12.2 \u5b9e\u73b0\u540e\u53f0\u6267\u884c"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u5b9e\u73b0\u540e\u53f0\u6267\u884c\r\nSpareTime.DoIt(()=>{});\n"})}),"\n",(0,i.jsx)(n.h2,{id:"123-\u5f00\u59cb\u4e00\u4e2a\u4efb\u52a1",children:"12.3 \u5f00\u59cb\u4e00\u4e2a\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'SpareTime.Start("\u4efb\u52a1\u6807\u8bc6");\n'})}),"\n",(0,i.jsx)(n.h2,{id:"124-\u6682\u505c\u4e00\u4e2a\u4efb\u52a1",children:"12.4 \u6682\u505c\u4e00\u4e2a\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'SpareTime.Stop("\u4efb\u52a1\u6807\u8bc6");\r\n// \u8fd8\u53ef\u4ee5\u6807\u8bb0\u4e00\u4e2a\u4efb\u52a1\u6267\u884c\u5931\u8d25\r\nSpareTime.Stop("\u4efb\u52a1\u6807\u8bc6", true);\n'})}),"\n",(0,i.jsx)(n.h2,{id:"125-\u53d6\u6d88\u4e00\u4e2a\u4efb\u52a1",children:"12.5 \u53d6\u6d88\u4e00\u4e2a\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'SpareTime.Cancel("\u4efb\u52a1\u540d\u79f0");\n'})}),"\n",(0,i.jsx)(n.h2,{id:"126-\u9500\u6bc1\u6240\u6709\u4efb\u52a1",children:"12.6 \u9500\u6bc1\u6240\u6709\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"SpareTime.Dispose();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"127-\u83b7\u53d6\u6240\u6709\u4efb\u52a1",children:"12.7 \u83b7\u53d6\u6240\u6709\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"var workers = SpareTime.GetWorkers();\n"})}),"\n",(0,i.jsx)(n.h2,{id:"128-\u83b7\u53d6\u5355\u4e2a\u4efb\u52a1",children:"12.8 \u83b7\u53d6\u5355\u4e2a\u4efb\u52a1"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'var worker = SpareTime.GetWorker("workerName");\n'})}),"\n",(0,i.jsxs)(n.h2,{id:"129-\u89e3\u6790-cron-\u8868\u8fbe\u5f0f",children:["12.9 \u89e3\u6790 ",(0,i.jsx)(n.code,{children:"Cron"})," \u8868\u8fbe\u5f0f"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'var nextTime = SpareTime.GetCronNextOccurrence("* * * * *");\n'})}),"\n",(0,i.jsxs)(n.h2,{id:"1210-backgroundservice-\u95f4\u9694\u5b9a\u65f6\u4efb\u52a1",children:["12.10 ",(0,i.jsx)(n.code,{children:"BackgroundService"})," \u95f4\u9694\u5b9a\u65f6\u4efb\u52a1"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u95f4\u9694\u6267\u884c\u4efb\u52a1\r\nawait SpareTime.DoAsync(1000, () =>\r\n{\r\n _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);\r\n}, stoppingToken);\n'})}),"\n",(0,i.jsxs)(n.h2,{id:"1211-backgroundservice-cron-\u5b9a\u65f6\u4efb\u52a1",children:["12.11 ",(0,i.jsx)(n.code,{children:"BackgroundService"})," ",(0,i.jsx)(n.code,{children:"Cron"})," \u5b9a\u65f6\u4efb\u52a1"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:' // \u6267\u884c Cron \u8868\u8fbe\u5f0f\u4efb\u52a1\r\nawait SpareTime.DoAsync("*/5 * * * * *", () =>\r\n{\r\n _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);\r\n}, stoppingToken, CronFormat.IncludeSeconds);\n'})})]})}function m(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},1151:(e,n,r)=>{r.d(n,{Z:()=>c,a:()=>o});var i=r(7294);const s={},a=i.createContext(s);function o(e){const n=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]); |