{"id":843,"date":"2021-09-13T09:49:13","date_gmt":"2021-09-13T01:49:13","guid":{"rendered":"http:\/\/www.wayln.com\/?p=843"},"modified":"2021-09-13T09:49:13","modified_gmt":"2021-09-13T01:49:13","slug":"%e5%b9%b6%e8%a1%8c%e7%bc%96%e7%a8%8b%e5%9f%ba%e7%a1%80-%e5%b9%b6%e8%a1%8c%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=843","title":{"rendered":"\u5e76\u884c\u7f16\u7a0b\u57fa\u7840\u2014\u2014\u5e76\u884c\u5904\u7406"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u5e76\u884c\u5904\u7406<\/a><ul><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_2\">1.1<\/span> \u95ee\u9898<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_2\">1.2<\/span> \u89e3\u51b3\u65b9\u6848<\/a><\/li><\/ul><\/li><\/ul><\/div>\n<p>\u5e76\u884c\u7f16\u7a0b\u7528\u6765\u62c6\u5206CPU\u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u5e76\u5c06\u4ed6\u4eec\u5206\u53d1\u7ed9\u591a\u4e2a\u7ebf\u7a0b\u3002<\/p>\n<h1><span id=\"i\">\u5e76\u884c\u5904\u7406<\/span><\/h1>\n<h2><span id=\"i-2\">\u95ee\u9898<\/span><\/h2>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u6570\u636e\u96c6\u5408\uff0c\u73b0\u5728\u9700\u8981\u5bf9\u6570\u636e\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\u3002\u8be5\u64cd\u4f5c\u4e3aCPU\u5bc6\u96c6\u578b\u64cd\u4f5c\uff0c\u4f1a\u6d88\u8017\u4e00\u4e9b\u65f6\u95f4\u3002<\/p>\n<h2><span id=\"i-3\">\u89e3\u51b3\u65b9\u6848<\/span><\/h2>\n<p>Parallel\u7c7b\u578b\u4e2d\u7684ForEach\u65b9\u6cd5\u662f\u4e3a\u6b64\u7c7b\u95ee\u9898\u91cf\u8eab\u5b9a\u5236\u7684\u3002\u4e0b\u9762\u7684\u793a\u4f8b\u63a5\u53d7\u4e00\u4e2a\u77e9\u9635\u96c6\u5408\uff0c\u5e76\u65cb\u8f6c\u5168\u90e8\u77e9\u9635<\/p>\n<pre><code class=\"language-CSharp line-numbers\">void RotateMatrices(IEnumerable&lt;Matrix&gt; matrices,float degrees)\n{\n    Parallel.Foreach(matrices,matrix=&gt;matrix.Rotate(degrees));\n}\n<\/code><\/pre>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u63d0\u65e9\u7ec8\u6b62\u5faa\u73af\uff0c\u6bd4\u5982\u5728\u9047\u5230\u65e0\u6548\u503c\u7684\u65f6\u5019\uff1a<\/p>\n<pre><code class=\"language-CSharp line-numbers\">void InvertMatrices(IEnumerable&lt;Matrix&gt; matrices)\n{\n    Parallel.ForEach(matrices,(matrix,state)=&gt;\n    {\n        if(!matrix.IsInvertible)\n            state.Stop();\n        else\n            matrix.Invert();\n    })\n}\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u53d6\u6d88\u6309\u94ae\u7fd8CancellationTokenSource,\u5e76\u53d6\u6d88\u5e76\u884c\u5faa\u73af<\/p>\n<pre><code class=\"language-CSharp line-numbers\">void RotateMatrices(IEnumerable&lt;Matrix&gt; matrices,float degrees,CancellationToken token)\n{\n    Parallel.ForEach(matrices,new ParallelOption{cancellationToken=token},matrix=&gt;matrix.Rotate(degrees));\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u5e76\u884c\u5904\u74061.1 \u95ee\u98981.2 \u89e3\u51b3\u65b9\u6848 \u5e76\u884c\u7f16\u7a0b\u7528\u6765\u62c6\u5206CPU\u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u5e76\u5c06\u4ed6\u4eec\u5206\u53d1\u7ed9\u591a\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,41,2],"tags":[],"class_list":["post-843","post","type-post","status-publish","format-standard","hentry","category-c","category-41","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=843"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/843\/revisions"}],"predecessor-version":[{"id":844,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/843\/revisions\/844"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}