{"id":763,"date":"2021-09-07T17:04:18","date_gmt":"2021-09-07T09:04:18","guid":{"rendered":"http:\/\/www.wayln.com\/?p=763"},"modified":"2021-09-07T19:10:03","modified_gmt":"2021-09-07T11:10:03","slug":"%e5%b9%b6%e8%a1%8c%e7%bc%96%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=763","title":{"rendered":"\u5e76\u884c\u7f16\u7a0b"},"content":{"rendered":"<p>\u5e76\u884c\u7f16\u7a0b\u4f1a\u901a\u8fc7\u6682\u65f6\u63d0\u5347CPU\u5229\u7528\u7387\uff0c\u6765\u63d0\u9ad8\u541e\u5410\u91cf\uff0c\u5bf9CPU\u7ecf\u5e38\u5f85\u547d\u7684\u5ba2\u6237\u7aef\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u662f\u6c42\u4e4b\u4e0d\u5f97\u7684\uff0c\u4f46\u5bf9\u4e8e\u670d\u52a1\u5668\u7aef\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u901a\u5e38\u5e76\u4e0d\u9002\u7528\u3002\u603b\u4f53\u6765\u770b\uff0c\u670d\u52a1\u5668\u4e0a\u7684\u5e76\u884c\u7f16\u7a0b\u4f1a\u4e0e\u5176\u5185\u7f6e\u7684\u5e76\u884c\u673a\u5236\u51b2\u7a81\uff0c\u56e0\u800c\u4e0d\u4f1a\u5e26\u6765\u4efb\u4f55\u5b9e\u9645\u76ca\u5904<\/p>\n<p>\u5e76\u884c\u673a\u5236\u5206\u4e3a\u6570\u636e\u5e76\u884c\u548c\u4efb\u52a1\u5e76\u884c\u3002<br \/>\n\u6570\u636e\u5e76\u884c\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0cParallel.ForEach\uff0cPLINQ<\/p>\n<p><strong>\u51c6\u5219\uff1a\u5404\u4e2a\u5de5\u4f5c\u5757\u5e94\u5f53\u5c3d\u53ef\u80fd\u5730\u76f8\u4e92\u72ec\u7acb<\/strong><\/p>\n<p>\u5bf9\u6240\u6709\u79cd\u7c7b\u7684\u5e76\u884c\u800c\u8a00\uff0c\u9519\u8bef\u5904\u7406\u90fd\u5927\u540c\u5c0f\u5f02\u3002\u56e0\u4e3a\u64cd\u4f5c\u662f\u5e76\u884c\u5904\u7406\uff0c\u6240\u4ee5\u6709\u53ef\u80fd\u51fa\u73b0\u591a\u4e2a\u5f02\u5e38\uff0c\u56e0\u800c\uff0c\u5c06\u4ed6\u4eec\u5305\u88c5\u5728\u4e00\u8d77\u7684AggregateException\u4f1a\u88ab\u629b\u51fa\u3002\u8fd9\u79cd\u884c\u4e3a\u5bf9\u4e8eParallel.ForEach\u3001Parallel.Invoke\u3001Task.Wait\u7b49\u90fd\u662f\u4e00\u6837\u7684\u3002AggregateException\u7c7b\u578b\u5177\u5907\u4e00\u4e9b\u5b9e\u7528\u7684Flatten\u65b9\u6cd5\u548cHandle\u65b9\u6cd5\uff0c\u53ef\u7528\u6765\u7b80\u5316\u9519\u8bef\u5904\u7406\u4ee3\u7801\u3002<\/p>\n<pre><code class=\"language-CSharp line-numbers\">try\n{\nParallel.Invoke(()=&gt;{throw new Exception();},()=&gt;{throw new Exception();});\n}\ncatch(AggregateException ex)\n{\nex.Handle(exception=&gt;{\nTrace.WriteLine(exception);\nreturn true;\n});\n<\/code><\/pre>\n<p><strong>\u4efb\u52a1\u4e0d\u5b9c\u8fc7\u77ed\uff0c\u4e5f\u4e0d\u5b9c\u8fc7\u957f<\/strong><br \/>\n\u5982\u679c\u4efb\u52a1\u8fc7\u77ed\uff0c\u90a3\u4e48\u5c06\u6570\u636e\u5206\u89e3\u4e3a\u4efb\u52a1\u5e76\u5728\u7ebf\u7a0b\u6c60\u4e2d\u8c03\u5ea6\u8fd9\u4e9b\u4efb\u52a1\u7684\u5f00\u9500\u5c06\u53d8\u5f97\u975e\u5e38\u5927\u3002\u5982\u679c\u4efb\u52a1\u8fc7\u957f\uff0c\u90a3\u4e48\u7ebf\u7a0b\u6c60\u65e0\u6cd5\u9ad8\u6821\u5730\u52a8\u6001\u8c03\u6574\u5176\u5de5\u4f5c\u5e73\u8861\u6027\u3002\u4e0e\u5176\u76f4\u63a5\u4f7f\u7528\u4efb\u52a1\uff0c\u4e0d\u5982\u7528Parallel\u7c7b\u578b\u6216PLINQ\u3002\u8fd9\u4e9b\u6bd4\u8f83\u9ad8\u5c42\u7684\u5e76\u884c\u5f62\u5f0f\u5185\u7f6e\u4e86\u5206\u533a\u529f\u80fd\uff0c\u53ef\u81ea\u52a8\u5904\u7406\u8fd9\u79cd\u95ee\u9898\uff08\u5e76\u5728\u8fd0\u884c\u65f6\u505a\u51fa\u5fc5\u8981\u8c03\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e76\u884c\u7f16\u7a0b\u4f1a\u901a\u8fc7\u6682\u65f6\u63d0\u5347CPU\u5229\u7528\u7387\uff0c\u6765\u63d0\u9ad8\u541e\u5410\u91cf\uff0c\u5bf9CPU\u7ecf\u5e38\u5f85\u547d\u7684\u5ba2\u6237\u7aef\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u662f\u6c42\u4e4b\u4e0d\u5f97\u7684\uff0c\u4f46\u5bf9\u4e8e\u670d\u52a1 [&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-763","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\/763","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=763"}],"version-history":[{"count":5,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/763\/revisions"}],"predecessor-version":[{"id":768,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/763\/revisions\/768"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}