{"id":1756,"date":"2015-01-17T00:54:10","date_gmt":"2015-01-16T16:54:10","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=1756"},"modified":"2015-01-27T21:06:21","modified_gmt":"2015-01-27T13:06:21","slug":"%e5%9f%ba%e4%ba%8e-qworker-%e7%9a%84%e5%a4%9a%e7%ba%bf%e7%a8%8b%e7%bc%96%e7%a8%8b-%e6%b8%85%e7%90%86%e7%8e%b0%e5%9c%ba","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=1756","title":{"rendered":"\u57fa\u4e8e QWorker \u7684\u591a\u7ebf\u7a0b\u7f16\u7a0b \u2013 \u6e05\u7406\u73b0\u573a"},"content":{"rendered":"<p>\u6709\u4eba\u96c7\u4f63\u4e86\u4e00\u4e9b\u5de5\u4eba\u5e72\u6d3b\uff0c\u4f46\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u4e2a\u4eba\u5728\u6240\u6709\u4f5c\u4e1a\u5b8c\u6210\u524d\uff0c\u6d88\u5931\u5728\u90a3\u84dd\u8272\u661f\u7403\u4e2d\u7684\u4eba\u6d77\u627e\u4e0d\u5230\u4e86\uff0c\u4e8e\u662f\uff0c\u60b2\u5267\u7684\u5de5\u4eba\u5728\u627e\u4ed6\u8981\u5de5\u94b1\u65f6\uff0c\u53d1\u73b0\u5df2\u7ecf\u65e0\u6cd5\u627e\u5230\u4eba\u4e86\uff0c\u4e8e\u662f\u5de5\u4eba\u66b4\u6012\uff0c\u8fdb\u884c\u75af\u72c2\u7684\u7834\u574f\uff0c\u7ed3\u679c\u5c31\u662f\u5f02\u5e38\u53d1\u751f\u4e86\u3002\u4e3a\u4e86\u907f\u514d\u5de5\u4eba\u7684\u66b4\u52a8\uff0c\u96c7\u4e3b\u5e94\u8be5\u5728\u6d88\u5931\u4e4b\u524d\uff0c\u6e05\u7406\u4f5c\u4e1a\uff0c\u4e0e\u5de5\u4eba\u8fdb\u884c\u7ed3\u7b97\uff0c\u8fd9\u6837\u624d\u80fd\u5efa\u8bbe\u548c\u8c10\u793e\u4f1a\u561b\u3002<\/p>\n<p>QWorker \u4e2d\u7684\u4f5c\u4e1a\u5728\u63d0\u4ea4\u7ed9 Workers \u8fd9\u4e2a\u5305\u5de5\u5934\u540e\uff0c\u4f5c\u4e1a\u80af\u5b9a\u4f1a\u8bbf\u95ee\u4e00\u4e9b\u5bf9\u8c61\u3001\u8bb0\u5f55\u6216\u666e\u901a\u7684\u53d8\u91cf\uff0c\u5728\u8fd9\u4e9b\u4e1c\u897f\u5931\u6548\u524d\uff0c\u80af\u5b9a\u8981\u5bf9\u76f8\u5173\u7684\u4f5c\u4e1a\u8fdb\u884c\u6e05\u7406\uff0c\u4ee5\u907f\u514dAV\u9519\u8bef\u3002\u5728 QWorker \u4e2d\uff0c\u63d0\u4f9b\u4e86 Clear \u7cfb\u5217\u51fd\u6570\u6765\u5b8c\u6210\u6b64\u9879\u64cd\u4f5c\u3002<\/p>\n<pre class=\"lang:delphi decode:true  \">    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6240\u6709\u4f5c\u4e1a&lt;\/summary&gt;\r\n    procedure Clear; overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u4e00\u4e2a\u5bf9\u8c61\u76f8\u5173\u7684\u6240\u6709\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AObject\"&gt;\u8981\u91ca\u653e\u7684\u4f5c\u4e1a\u5904\u7406\u8fc7\u7a0b\u5173\u8054\u5bf9\u8c61&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AMaxTimes\"&gt;\u6700\u591a\u6e05\u9664\u7684\u6570\u91cf\uff0c\u5982\u679c&lt;0\uff0c\u5219\u5168\u6e05&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    \/\/\/ &lt;remarks&gt;\u4e00\u4e2a\u5bf9\u8c61\u5982\u679c\u8ba1\u5212\u4e86\u4f5c\u4e1a\uff0c\u5219\u5728\u81ea\u5df1\u91ca\u653e\u524d\u5e94\u8c03\u7528\u672c\u51fd\u6570\u4ee5\u6e05\u9664\u5173\u8054\u7684\u4f5c\u4e1a\uff0c\r\n    \/\/\/ \u5426\u5219\uff0c\u672a\u5b8c\u6210\u7684\u4f5c\u4e1a\u53ef\u80fd\u4f1a\u89e6\u53d1\u5f02\u5e38\u3002&lt;\/remarks&gt;\r\n    function Clear(AObject: Pointer; AMaxTimes: Integer = -1): Integer;\r\n      overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6240\u6709\u6295\u5bc4\u7684\u6307\u5b9a\u8fc7\u7a0b\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AProc\"&gt;\u8981\u6e05\u9664\u7684\u4f5c\u4e1a\u6267\u884c\u8fc7\u7a0b&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AData\"&gt;\u8981\u6e05\u9664\u7684\u4f5c\u4e1a\u9644\u52a0\u6570\u636e\u6307\u9488\u5730\u5740\uff0c\u5982\u679c\u503c\u4e3aPointer(-1)\uff0c\r\n    \/\/\/ \u5219\u6e05\u9664\u6240\u6709\u7684\u76f8\u5173\u8fc7\u7a0b\uff0c\u5426\u5219\uff0c\u53ea\u6e05\u9664\u9644\u52a0\u6570\u636e\u5730\u5740\u4e00\u81f4\u7684\u8fc7\u7a0b&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AMaxTimes\"&gt;\u6700\u591a\u6e05\u9664\u7684\u6570\u91cf\uff0c\u5982\u679c&lt;0\uff0c\u5219\u5168\u6e05&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    function Clear(AProc: TQJobProc; AData: Pointer; AMaxTimes: Integer = -1)\r\n      : Integer; overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6307\u5b9a\u4fe1\u53f7\u5173\u8054\u7684\u6240\u6709\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"ASingalName\"&gt;\u8981\u6e05\u9664\u7684\u4fe1\u53f7\u540d\u79f0&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    function Clear(ASignalName: QStringW): Integer; overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6307\u5b9a\u4fe1\u53f7\u5173\u8054\u7684\u6240\u6709\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"ASingalId\"&gt;\u8981\u6e05\u9664\u7684\u4fe1\u53f7ID&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    function Clear(ASignalId: Integer): Integer; overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6307\u5b9a\u53e5\u67c4\u5bf9\u5e94\u7684\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"ASingalId\"&gt;\u8981\u6e05\u9664\u7684\u4f5c\u4e1a\u53e5\u67c4&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    procedure ClearSingleJob(AHandle: IntPtr); overload;\r\n    \/\/\/ &lt;summary&gt;\u6e05\u9664\u6307\u5b9a\u7684\u53e5\u67c4\u5217\u8868\u4e2d\u5bf9\u5e94\u7684\u4f5c\u4e1a&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AHandles\"&gt;\u7531Post\/At\u7b49\u6295\u9012\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\u5217\u8868&lt;\/param&gt;\r\n    \/\/\/ &lt;parma name=\"ACount\"&gt;AHandles\u5bf9\u5e94\u7684\u53e5\u67c4\u4e2a\u6570&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u8fd4\u56de\u5b9e\u9645\u6e05\u9664\u7684\u4f5c\u4e1a\u6570\u91cf&lt;\/returns&gt;\r\n    function ClearJobs(AHandles: PIntPtr; ACount: Integer): Integer; overload;<\/pre>\n<p>\u901a\u8fc7\u51fd\u6570\u7684\u6ce8\u91ca\uff0c\u6211\u76f8\u4fe1\u5927\u5bb6\u5df2\u7ecf\u660e\u767d\u5404\u4e2a\u6e05\u7406\u51fd\u6570\u90fd\u662f\u5e72\u561b\u7528\u7684\u4e86\uff0c\u7528\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u8c03\u7528\u00a0Workers.ClearXXX(&#8230;) \u6267\u884c\u6e05\u7406\u8fc7\u7a0b\u5c31\u597d\u3002<\/p>\n<p>\u5982\u679c\u662f\u5206\u7ec4\u4f5c\u4e1a\uff0c\u90a3\u4e48\u6211\u4eec\u8be5\u5982\u4f55\u600e\u4e48\u529e\uff1f TQJobGroup \u63d0\u4f9b\u4e86\u4e00\u4e2a Cancel \u51fd\u6570\u6765\u5b8c\u6210\u8fd9\u9879\u5de5\u4f5c\u3002Cancel \u51fd\u6570\u5c06\u53d6\u6d88\u540e\u7eed\u4f5c\u4e1a\u7684\u6267\u884c\uff0c\u6ce8\u610f\u5176\u4e2d\u7684 AWaitDone \u53c2\u6570\u8981\u614e\u7528\uff0c\u5982\u679c\u5728\u5206\u7ec4\u4f5c\u4e1a\u4e2d\u7684\u4f5c\u4e1a\u6267\u884c Cancel \u65f6\uff0c\u5fc5\u9700\u4f20\u9012\u4e3a False\uff0c\u5426\u5219\u4f1a\u6b7b\u7b49\u81ea\u5df1\u7ed3\u675f\u800c\u4e0d\u53ef\u5f97\u3002\u81f3\u4e8e\u5176\u5b83\u573a\u5408\uff0c\u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u53ef\u3002<\/p>\n<p>\u603b\u4e4b\uff0c\u4e00\u4e2a\u7a33\u5b9a\u53ef\u9760\u7684\u7a0b\u5e8f\uff0c\u53ca\u65f6\u6e05\u7406\u4e0d\u9700\u8981\u7684\u8d44\u6e90\u662f\u4e00\u4e2a\u826f\u597d\u7684\u5de5\u4f5c\u4e60\u60ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4eba\u96c7\u4f63\u4e86\u4e00\u4e9b\u5de5\u4eba\u5e72\u6d3b\uff0c\u4f46\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9,6],"tags":[57],"class_list":["post-1756","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qworker","tag-57"],"views":3630,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1756"}],"version-history":[{"count":4,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1756\/revisions"}],"predecessor-version":[{"id":2396,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1756\/revisions\/2396"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}