{"id":22,"date":"2025-09-28T13:08:33","date_gmt":"2025-09-28T05:08:33","guid":{"rendered":"https:\/\/www.zshtys888.com\/?p=22"},"modified":"2025-09-28T13:08:33","modified_gmt":"2025-09-28T05:08:33","slug":"runtime-async-%e6%ad%a5%e5%85%a5%e9%ab%98%e6%80%a7%e8%83%bd%e5%bc%82%e6%ad%a5%e6%97%b6%e4%bb%a3","status":"publish","type":"post","link":"https:\/\/www.zshtys888.com\/index.php\/2025\/09\/28\/runtime-async-%e6%ad%a5%e5%85%a5%e9%ab%98%e6%80%a7%e8%83%bd%e5%bc%82%e6%ad%a5%e6%97%b6%e4%bb%a3\/","title":{"rendered":"Runtime Async &#8211; \u6b65\u5165\u9ad8\u6027\u80fd\u5f02\u6b65\u65f6\u4ee3"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"1351914177\">\u540c\u6b65\u4ee3\u7801\u548c\u5f02\u6b65\u4ee3\u7801<a href=\"https:\/\/www.cnblogs.com\/hez2010\/p\/19097937\/runtime-async#1351914177\">#<\/a><\/h2>\n\n\n\n<p>\u4e00\u822c\u800c\u8a00\uff0c\u4ee3\u7801\u53ef\u5206\u4e3a\u540c\u6b65\u4e0e\u5f02\u6b65\u4e24\u7c7b\u3002\u4e24\u8005\u540c\u6837\u9700\u8981\u7b49\u5f85\u64cd\u4f5c\u5b8c\u6210\uff1a\u540c\u6b65\u4f1a\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\uff0c\u76f4\u81f3\u64cd\u4f5c\u7ed3\u675f\u540e\u518d\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u903b\u8f91\uff1b\u5f02\u6b65\u5219\u4e0d\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\uff0c\u800c\u662f\u5728\u53d1\u8d77\u64cd\u4f5c\u65f6\u9884\u5148\u6ce8\u518c\u5b8c\u6210\u540e\u7684\u5904\u7406\u903b\u8f91\uff0c\u5f85\u64cd\u4f5c\u5b8c\u6210\u65f6\u7531\u64cd\u4f5c\u672c\u8eab\u6216\u5916\u90e8\u673a\u5236\u89e6\u53d1\u8be5\u903b\u8f91\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\u8fd9\u5c31\u5e26\u6765\u4e00\u4e2a\u95ee\u9898\uff0c\u90a3\u5c31\u662f\u540c\u6b65\u4ee3\u7801\u548c\u5f02\u6b65\u4ee3\u7801\u7684\u5199\u6cd5\u662f\u5b8c\u5168\u4e0d\u540c\u7684\uff01<\/p>\n\n\n\n<p>\u5728 async\/await \u4e4b\u524d\uff0c\u5f02\u6b65\u7f16\u7a0b\u901a\u5e38\u5c06\u56de\u8c03\u51fd\u6570\u4ea4\u7ed9\u5f02\u6b65\u64cd\u4f5c\uff0c\u4ee5\u4fbf\u5728\u5b8c\u6210\u65f6\u89e6\u53d1\u9884\u5148\u7f16\u5199\u7684\u903b\u8f91\u3002\u5176\u540e\u679c\u662f\uff1a\u903b\u8f91\u88ab\u62c6\u6563\u5230\u5404\u4e2a\u56de\u8c03\u4e2d\uff0c\u6216\u5c42\u5c42\u5d4c\u5957\u6210\u201c\u56de\u8c03\u5730\u72f1\u201d\u3002\u6b64\u5916\uff0c\u56de\u8c03\u5fc5\u987b\u7531\u8c03\u7528\u65b9\u5411\u88ab\u8c03\u7528\u65b9\u4f20\u9012\uff0c\u8feb\u4f7f\u8c03\u7528\u65b9\u63d0\u524d\u4e86\u89e3\u5e76\u643a\u5e26\u5b8c\u6210\u540e\u8981\u5524\u9192\u7684\u4ee3\u7801\uff0c\u8fd9\u4e0e\u81ea\u7136\u7684\u601d\u7ef4\u65b9\u5f0f\u76f8\u6096\u2014\u2014\u540c\u4e00\u9879\u64cd\u4f5c\u7684\u5b8c\u6210\u53ef\u80fd\u4f1a\u88ab\u591a\u4e2a\u4f4d\u7f6e\u540c\u65f6\u5173\u5fc3\uff0c\u800c\u53d1\u8d77\u8be5\u64cd\u4f5c\u7684\u4ee3\u7801\u4e0d\u5e94\u5bf9\u7b49\u5f85\u5176\u5b8c\u6210\u7684\u4ee3\u7801\u4ea7\u751f\u4efb\u4f55\u5f62\u5f0f\u7684\u4f9d\u8d56\u3002<\/p>\n\n\n\n<p>async\/await \u7684\u51fa\u73b0\u5219\u4ece\u6839\u672c\u4e0a\u6539\u53d8\u4e86\u8fd9\u4e00\u70b9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2362801386\">async\/await<a href=\"https:\/\/www.cnblogs.com\/hez2010\/p\/19097937\/runtime-async#2362801386\">#<\/a><\/h2>\n\n\n\n<p>\u73b0\u5982\u4eca\u6211\u4eec\u63d0\u5230 async\/await\uff0c\u5c3d\u7ba1\u5b83\u4ecd\u5f52\u5165 stackless coroutine \u8303\u7574\uff0c\u4f46\u5df2\u4e0d\u540c\u4e8e\u65e9\u671f\u90a3\u79cd\u5728\u9012\u5f52\u3001\u9519\u8bef\u5904\u7406\u4e0e\u8c03\u7528\u6808\u8ffd\u8e2a\u4e0a\u5c40\u9650\u9887\u591a\u7684\u5f62\u6001\uff1b\u8fd9\u4e9b\u5c40\u9650\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u5df2\u7ecf\u88ab\u514b\u670d\u3002<\/p>\n\n\n\n<p>.NET \u5bf9 async\/await \u7684\u652f\u6301\uff0c\u672c\u8d28\u4e0a\u662f\u7f16\u8bd1\u5668\u5bf9\u5f02\u6b65\u65b9\u6cd5\u8fdb\u884c\u4e00\u79cd CPS \u98ce\u683c\u7684\u53d8\u6362\uff0c\u5e76\u5c06\u5176\u843d\u5730\u4e3a\u53ef\u6062\u590d\u7684\u72b6\u6001\u673a\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\uff0c\u5f53\u9047\u5230\u5982\u4e0b\u4ee3\u7801\u65f6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Copy<code>async Task Foo()\n{\n    A();\n    await B();\n    C();\n    await E();\n    F();\n}\n<\/code><\/pre>\n\n\n\n<p>\u7f16\u8bd1\u5668\u4f1a\u4ee5 await \u4e3a\u5207\u5206\u70b9\u751f\u6210\u82e5\u5e72\u201c\u7eed\u4f53\u201d\uff08continuation\uff09\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u7eed\u4f53\u6355\u83b7\u6240\u9700\u7684\u5c40\u90e8\u53d8\u91cf\u4e0e\u6267\u884c\u4e0a\u4e0b\u6587\uff0c\u4f7f\u5176\u65e2\u53ef\u88ab\u72ec\u7acb\u8c03\u5ea6\u6267\u884c\uff0c\u540c\u65f6\u4ecd\u80fd\u8bbf\u95ee await \u4e4b\u524d\u7684\u72b6\u6001\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u53ea\u9700\u5728\u88ab\u7b49\u5f85\u7684\u64cd\u4f5c\u5b8c\u6210\u65f6\u5c06\u4e0b\u4e00\u4e2a\u7eed\u4f53\u4ea4\u7ed9\u8c03\u5ea6\u5668\uff0c\u5c31\u53ef\u4ee5\u6309\u81ea\u5b9a\u4e49\u7b56\u7565\u81ea\u7531\u5730\u63a8\u8fdb\u540e\u7eed\u4ee3\u7801\u7684\u6267\u884c\u3002\u5f02\u6b65\u65b9\u6cd5\u5728\u6267\u884c\u5230\u6bcf\u4e00\u5904 await \u65f6\u4f1a\u88ab\u6682\u505c\uff0c\u7b49\u5f85\u540e\u7eed\u903b\u8f91\u88ab\u91cd\u65b0\u8c03\u5ea6\u7ee7\u7eed\u6267\u884c\u3002\u56e0\u6b64\uff0cawait \u5b9e\u9645\u4e0a\u4e5f\u6807\u6ce8\u4e86\u5f02\u6b65\u65b9\u6cd5\u7684\u6f5c\u5728\u6682\u505c\u70b9\u3002<\/p>\n\n\n\n<p>\u5728 C# \u7684\u7b2c\u4e00\u7248 async\/await \u4e2d\uff0c\u8fd9\u4e00\u673a\u5236\u5177\u4f53\u62bd\u8c61\u4e3a\u7f16\u8bd1\u671f\u751f\u6210\u7684\u72b6\u6001\u673a\uff08\u5b9e\u73b0 IAsyncStateMachine\uff09\uff0c\u7531\u8c03\u5ea6\u5668\/\u540c\u6b65\u4e0a\u4e0b\u6587\u9a71\u52a8 MoveNext \u9010\u6b65\u63a8\u8fdb\uff0c\u4ece\u800c\u4fdd\u8bc1\u6bcf\u4e2a\u4ee3\u7801\u7247\u6bb5\u5728\u524d\u4e00\u4e2a\u5f02\u6b65\u64cd\u4f5c\u5b8c\u6210\u540e\u88ab\u6b63\u786e\u8c03\u5ea6\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u7136\u800c\u4e00\u76f4\u4ee5\u6765 C# \u7684 async\/await \u5b9e\u73b0\u90fd\u5b58\u5728\u4e00\u4e2a\u8fb9\u754c\u4e0a\u7684\u95ee\u9898\uff1aC# \u7f16\u8bd1\u5668\u4ee5\u65b9\u6cd5\u4e3a\u7f16\u8bd1\u5355\u4f4d\uff0c\u65e2\u65e0\u6cd5\u8de8\u8d8a\u65b9\u6cd5\u8fb9\u754c\u5168\u9762\u6d1e\u5bdf\u88ab\u8c03\u7528\u65b9\u6cd5\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u4e5f\u4e0d\u4f1a\u6539\u53d8 managed ABI \u53bb\u64c5\u81ea\u4fee\u6539\u5f53\u524d\u65b9\u6cd5\u7684\u7b7e\u540d\u3002\u56e0\u6b64\uff0c\u5728\u5f62\u6210\u5f02\u6b65\u8c03\u7528\u94fe\u65f6\uff0c\u901a\u5e38\u6bcf\u4e2a async \u65b9\u6cd5\u90fd\u4f1a\u62e5\u6709\u81ea\u5df1\u7684\u72b6\u6001\u673a\uff1b\u800c\u5728\u7f3a\u4e4f\u8de8\u8fb9\u754c\u5168\u91cf\u4fe1\u606f\u7684\u60c5\u51b5\u4e0b\uff0c\u8c03\u7528\u65b9\u4f1a\u751f\u6210\u8f83\u4e3a\u901a\u7528\u7684\u8def\u5f84\u6765\u8986\u76d6\u5f02\u5e38\u4e0e\u6682\u505c\u7b49\u60c5\u5f62\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5373\u4fbf\u76ee\u6807\u65b9\u6cd5\u5728\u591a\u6570\u60c5\u51b5\u4e0b\u5e76\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u8c03\u7528\u70b9\u4ecd\u4f1a\u4fdd\u7559\u5f02\u5e38\u6355\u83b7\u4e0e\u6062\u590d\u8def\u5f84\uff1b\u53c8\u6216\u8005\u76ee\u6807\u65b9\u6cd5\u5f88\u53ef\u80fd\u4e0d\u4f1a\u6682\u505c\uff0c\u8c03\u7528\u70b9\u4e5f\u4f1a\u4fdd\u7559\u76f8\u5e94\u7684\u6682\u505c\/\u6062\u590d\u5206\u652f\u4ee5\u4fdd\u8bc1\u8bed\u4e49\u6b63\u786e\uff1b\u53c8\u6216\u8005\u6bd4\u5982\u5f02\u6b65\u8c03\u7528\u94fe\u4e2d\u6bcf\u4e00\u5904\u5f02\u6b65\u8c03\u7528\u90fd\u901a\u8fc7 await \u5bf9\u5176\u7ed3\u679c\u76f4\u63a5\u8fdb\u884c\u7b49\u5f85\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b9e\u9645\u4e0a\u5e76\u4e0d\u9700\u8981\u5c06\u5f02\u6b65\u64cd\u4f5c\u7684\u7ed3\u679c\u5305\u88c5\u8fdb Task \u4e4b\u7c7b\u7684\u7c7b\u578b\uff0c\u7136\u800c\u7531\u4e8e\u9700\u8981\u4fdd\u6301 managed ABI\uff0c\u7f16\u8bd1\u5668\u4ecd\u7136\u9700\u8981\u5c06\u6bcf\u4e00\u6b65\u7684\u7ed3\u679c\u5305\u88c5\u8fdb Task \u91cc\u9762\u53bb\uff1b\u518d\u6bd4\u5982\u5bf9\u4e8e\u5b9e\u9645\u4e0a\u6ca1\u6709\u540c\u6b65\u4e0a\u4e0b\u6587\u7684\u60c5\u51b5\uff0c\u7f16\u8bd1\u5668\u4ecd\u7136\u9700\u8981\u4ea7\u751f\u5907\u4efd\/\u6062\u590d\u540c\u6b65\u4e0a\u4e0b\u6587\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u95ee\u9898\u4f7f\u5f97\u7f16\u8bd1\u540e\u7684 C# \u4ee3\u7801\u96be\u4ee5\u88ab JIT \u4f18\u5316\uff0c\u540c\u65f6\u8fd8\u4f1a\u4ea7\u751f\u591a\u4f59\u7684 Task \u5bf9\u8c61\u5206\u914d\uff0c\u4ece\u800c\u5bfc\u81f4 C# \u4e2d\u5f02\u6b65\u4ee3\u7801\u7684\u6027\u80fd\u4e00\u76f4\u65e0\u6cd5\u4e0e\u540c\u6b65\u4ee3\u7801\u76f8\u5339\u654c\uff0c\u751a\u81f3\u51fa\u73b0 ValueTask \u8fd9\u79cd\u4e13\u95e8\u4e3a\u4e86\u6d88\u9664\u5206\u914d\u800c\u8bde\u751f\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>.NET \u56e2\u961f\u81ea\u4ece .NET 8 \u5f00\u59cb\u5c1d\u8bd5\u5bf9\u8fd9\u4e00\u73b0\u72b6\u8fdb\u884c\u6539\u8fdb\u3002\u5148\u662f\u5bf9 Green Thread \u65b9\u6848\uff08\u4e0e goroutine\u3001Java \u7684 Virtual Thread \u65b9\u6848\u76f8\u540c\uff09\u8fdb\u884c\u5b9e\u9a8c\uff0c\u7ed3\u679c\u76f8\u6bd4\u76ee\u524d\u7684 async\/await \u4e0d\u4ec5\u6027\u80fd\u6ca1\u6709\u63d0\u5347\uff0c\u53cd\u800c\u5728\u8de8 runtime \u8fb9\u754c\u8c03\u7528\u573a\u666f\u5b58\u5728\u4e0d\u53ef\u63a5\u53d7\u7684\u6027\u80fd\u56de\u9000\u548c\u8c03\u5ea6\u95ee\u9898\u3002\u5728\u7ed3\u675f\u8fd9\u4e00\u5931\u8d25\u7684\u5b9e\u9a8c\u4e4b\u540e\uff0c\u4ece .NET 9 \u5f00\u59cb\u904d\u5168\u529b\u5411\u7740\u6539\u8fdb async\/await \u672c\u8eab\u7684\u65b9\u5411\u63a2\u7d22\uff0c\u4e8e\u662f\uff0c\u5168\u65b0\u7684 Runtime Async \u5230\u6765\u4e86\u3002\u987a\u5e26\u4e00\u63d0\uff0cRuntime Async \u6700\u65e9\u7684\u540d\u5b57\u53eb\u505a Async 2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u6b65\u4ee3\u7801\u548c\u5f02\u6b65\u4ee3\u7801# \u4e00\u822c\u800c\u8a00\uff0c\u4ee3\u7801\u53ef\u5206\u4e3a\u540c\u6b65\u4e0e\u5f02\u6b65\u4e24\u7c7b\u3002\u4e24\u8005\u540c\u6837\u9700\u8981\u7b49\u5f85\u64cd\u4f5c\u5b8c\u6210\uff1a\u540c\u6b65\u4f1a\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\uff0c\u76f4\u81f3\u64cd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":2,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":24,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/posts\/22\/revisions\/24"}],"wp:attachment":[{"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zshtys888.com\/index.php\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}