{"id":364598,"date":"2024-05-21T02:20:11","date_gmt":"2024-05-21T02:20:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=364598"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=364598","title":{"rendered":"<span>Async\/Await \u0438\u0437 C#. \u0413\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0438 \u0434\u043b\u044f \u043d\u0430\u0441<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0440\u0438\u0441\u043a\u043d\u0443 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u041f\u043e\u0441\u0442\u0430: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">How Async\/Await Really Works in C#<\/a>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/782762\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u201c\u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434\u201d. \u0422\u0430\u043a\u0436\u0435, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e) <a href=\"https:\/\/habr.com\/ru\/articles\/784072\/\" rel=\"noopener noreferrer nofollow\">\u0441 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 SynchronizationContext<\/a> \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0440 \u044d\u0442\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430.<\/p>\n<p>\u042d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434. \u042d\u0442\u043e \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u041f\u043e\u0441\u0442\u0430 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f (\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u0438) \u043c\u043e\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u0435\u0445 \u043c\u044b\u0441\u043b\u0435\u0439 \u0438 \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0445\u043e\u0442\u0435\u043b \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0434\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 Stephen Toub.<\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u044f \u043f\u0438\u0448\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438 \u043a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0432\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e \u0442\u0435\u043c\u0435, \u0430 \u0432\u044b \u043e\u0434\u043e\u0431\u0440\u044f\u0435\u0442\u0435 \u0438\u043b\u0438 \u043a\u0440\u0438\u0442\u0438\u043a\u0443\u0435\u0442\u0435\/\u0443\u0442\u043e\u0447\u043d\u044f\u0435\u0442\u0435 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u0430\u043c\u044b\u043c \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0438 \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0440\u043e\u0434\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430 \u0435\u0449\u0435 \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u043d\u0443\u044e \u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0438\u0437 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0438\u043b\u0438 \u0442\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043d\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 Async\/Await \u0432 C#.<\/p>\n<hr\/>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 Async\/Await \u0432 C#. \u041d\u043e \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0441 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c:<\/p>\n<h2>\u0418\u0437\u0432\u0438\u043b\u0438\u0441\u0442\u044b\u0439 \u043f\u0443\u0442\u044c \u0432 \u043c\u0438\u0440 async \/ await<\/h2>\n<p>\u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435\u043c \u041f\u043e\u0441\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0430\u0432\u0442\u043e\u0440 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0443\u0436\u0435 \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0446\u0435\u043b\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u0438 \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 Async\/Await \u0432 C#. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0432 \u043a\u043e\u0434\u0435. \u041d\u043e \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0438\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f) \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\/\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b-\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 C#, \u043a\u0430\u043a \u0440\u0430\u0437 \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 (\u0445\u043e\u0442\u044f \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0445) \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c.<\/p>\n<p>\u041a\u0430\u043a \u043f\u0438\u0448\u0435\u0442 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435, <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/understanding-the-whys-whats-and-whens-of-valuetask\/\" rel=\"noopener noreferrer nofollow\">Understanding the Whys, Whats, and Whens of ValueTask<\/a> (\u0442\u0430\u043c, \u043a\u0441\u0442\u0430\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0438 \u043a\u0430\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445):<\/p>\n<blockquote>\n<p>This is, after all, how we write synchronous code (e.g. Result result = SomeOperation();), and it naturally translates to the world of async \/ await.<\/p>\n<\/blockquote>\n<p>\u041f\u043e \u043c\u043e\u0438\u043c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u043b \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0438\u0437\u0432\u0438\u043b\u0438\u0441\u0442\u044b\u0439 \u043f\u0443\u0442\u044c \u0432 &#171;\u043c\u0438\u0440 async\/await&#187;. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0440\u0435\u0448\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u043c\u044b \u043a\u0430\u043a-\u0442\u043e \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u044d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u044b \u0411\u0415\u0417 \u043d\u0430\u0448\u0435\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u041d\u043e \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043c\u044b \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043d\u0430\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u0442\u044c \u0443\u0441\u0438\u043b\u0438\u0435 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0441 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u043a\u0443\u0440\u0441\u0430 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0430\u0432\u0442\u043e\u0440. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0441\u044f \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0432 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0441\u043c\u0435\u043d\u0430 \u044d\u043a\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u0431\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0435 \u0438\u0437\u043d\u0443\u0442\u0440\u0438, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0423\u0416\u0415 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0432\u0441\u0435\u043e\u0431\u044a\u0435\u043c\u043b\u044e\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430, \u0432 \u043f\u0435\u0434\u0430\u0433\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043b\u044f\u0445:<\/p>\n<blockquote>\n<p> &#8230; is only being done in the name of pedagogy &#8230;<\/p>\n<p>&#8230; we\u2019ll do the pedagogical thing and just implement a simple version. &#8230;<\/p>\n<\/blockquote>\n<p>\u0418 \u043f\u0438\u0448\u0435\u043c, \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0438\u0434\u0435\u044f\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u0438 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u0431\u044b \u0438\u0437\u043d\u0443\u0442\u0440\u0438, \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044e \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u044f\u0434\u0440\u0430 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a .Net \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0437\u0430\u043c\u0435\u043d\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>class MyTask \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e(\u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e) \u043a\u043b\u0430\u0441\u0441\u0430 Task<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cs\">public void ContinueWith(Action&lt;MyTask> action) public void SetResult() => Complete(null); public void SetException(Exception error) => Complete(error); private void Complete(Exception? error)  static Task IterateAsync(IEnumerable&lt;Task> tasks) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 (\u0442\u0438\u043f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441): public struct MyTaskMethodBuilder \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 TaskMethodBuilder<\/p>\n<\/li>\n<li>\n<p>class MyThreadPool \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 ThreadPool<\/p>\n<\/li>\n<\/ul>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430<\/h2>\n<p>\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0430\u043a\u0443\u0440\u0441\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0435\u0445\u043d\u0438\u043a\u0438, \u2026 \u043d\u0430\u0437\u043e\u0432\u0438\u0442\u0435, \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e) \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430 \u043a\u0430\u0434\u0440\u043e\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u044f\u0435\u0442. \u041d\u043e \u0430\u0432\u0442\u043e\u0440 \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043d\u0430\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u041f\u043e\u0441\u0442\u0430:<\/p>\n<pre><code class=\"cs\">\/\/ Asynchronously copy all data from source to destination. public async Task CopyStreamToStreamAsync(Stream source, Stream destination) {     var buffer = new byte[0x1000];     int numRead;     while ((numRead = await source.ReadAsync(buffer, 0, buffer.Length)) != 0)     {         await destination.WriteAsync(buffer, 0, numRead);     } }<\/code><\/pre>\n<p>\u0418 \u044f, \u043d\u0430\u0432\u0435\u0440\u043d\u043e, \u0442\u043e\u0436\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044f\u0441\u043d\u043e \u0438\u0437\u044a\u044f\u0441\u043d\u044f\u044e\u0441\u044c \u043f\u043e\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043f\u0435\u0448\u0443 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442, \u0437\u0434\u0435\u0441\u044c, \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0447\u0442\u043e \u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442 \u0441 \u0442\u0430\u0432\u0442\u043e\u043b\u043e\u0433\u0438\u0435\u0439: \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0434\u0430 \u0438 \u043e\u0431\u044a\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u043d\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0432\u0438\u0434\u0438\u043c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0410\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u043c \u043a\u043e\u0434 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c (\u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438) \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0432 \u043e\u0431\u0449\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043d\u0435 \u0443\u0434\u043e\u0441\u0443\u0436\u0438\u043b\u0441\u044f \u0434\u0430\u0436\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0433\u0434\u0435-\u0442\u043e, \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430, \u0438\u043d\u0430\u0447\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 async \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430, \u0430 \u0432\u043e\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e! \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0434\u0430\u043b\u0435\u0435, \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442, \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043b\u044e\u0431\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0443\u044e async (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e) \u0438 \u043c\u044b, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0442\u043e\u0436\u0435 \u0434\u043e\u0431\u0435\u0440\u0435\u043c\u0441\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">How Async\/Await Really Works in C#<\/a> \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 async, \u0435\u0441\u043b\u0438 \u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a \u043e\u0431\u044a\u0435\u043c\u0443 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h2>\u041a\u0430\u043a C# \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441\u043f\u0430\u0441\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043a\u043e\u043b\u0431\u0435\u043a\u043e\u0432, \u043d\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/h2>\n<p>\u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f: <strong>C# Iterators to the Rescue.<\/strong><\/p>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u043a: C# \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c (\u0441\u043f\u0430\u0441\u043b\u0438 \u043d\u0430\u0441). \u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u0438\u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u043f\u0430\u0441\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c callbacks (\u043a\u043e\u043b\u0431\u0435\u043a\u0438) \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/782762\/\" rel=\"noopener noreferrer nofollow\">Async\/Await \u0432 C#. \u0423\u0440\u043e\u043a\u0438 \u043f\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e<\/a> \u043c\u044b \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u0412\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f Async\/Await\u00bb, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u00ab\u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 yield return \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 IEnumerable&lt;> \u0441\u043f\u0438\u0441\u043a\u0430\u00bb \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 Async\/Await.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 Async, \u0430 \u043a\u0430\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043b\u043e\u0433\u0438\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u044b \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u043c\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0442\u0435 \u0438\u0434\u0435\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u0441\u0442\u0430 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0434\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0438, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u0410\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0441\u0442\u0438\u043b\u0435 \u00abyield return \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 IEnumerable&lt;> \u0441\u043f\u0438\u0441\u043a\u0430\u00bb:<\/p>\n<pre><code class=\"cs\">    static IEnumerable&lt;Task> Impl(Stream source, Stream destination)     {         var buffer = new byte[0x1000];         while (true)         {             Task&lt;int> read = source.ReadAsync(buffer, 0, buffer.Length);             yield return read;             int numRead = read.Result;             if (numRead &lt;= 0)             {                 break;             }              Task write = destination.WriteAsync(buffer, 0, numRead);             yield return write;             write.Wait();         }     }<\/code><\/pre>\n<p>\u042f \u0434\u0443\u043c\u0430\u044e, \u0438\u0434\u0435\u044f \u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u0430, \u043d\u043e \u044f \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u044e \u0435\u0435 \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439. \u0421\u0443\u0442\u044c \u0438\u0434\u0435\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e yield return \u0438 \u0434\u0430\u043b\u0435\u0435 \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e yield return \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 case X-STATE: \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 switch \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0442\u0435\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0442\u043e\u0436\u0435 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u043b, \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">static Task CopyStreamToStreamAsync(Stream source, Stream destination) {     return IterateAsync(Impl(source, destination));      \/\/ ... }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f Impl() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c yield return, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c \u0438\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 foreach. \u041d\u043e \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f foreach! \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 CopyStreamToStreamAsync(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443 Impl(), \u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0442\u043e \u0442\u0440\u044e\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Impl().<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043c\u044b \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043c \u043a \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0436\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 async \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 \u0442\u0435\u043c \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u043b\u044f \u00ab\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 yield return \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 IEnumerable&lt;> \u0441\u043f\u0438\u0441\u043a\u0430\u00bb \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f async \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u043e \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0435\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0441 \u0446\u0438\u043a\u043b\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e \u043c\u0435\u0441\u0442\u0443 \u0432\u044b\u0437\u043e\u0432\u0430. \u041d\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u043e\u0432\u044b async \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0438\u0441\u044c \u043e\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438 \u044d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u043e\u0439 \u0434\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u043e\u0441\u043c\u044b\u0441\u043b\u0438\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 Async\/Await. \u0422\u043e\u043b\u044c\u043a\u043e \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u0441\u0442\u0430 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0430 \u0431\u044b\u043b\u0430 \u0434\u0430\u0432\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0430 \u0438 \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0435 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a, async\/await \u0432\u043e\u0440\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0441\u0446\u0435\u043d\u0443 (\u043f\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0430\u0432\u0442\u043e\u0440\u0430 \u041f\u043e\u0441\u0442\u0430):<\/p>\n<blockquote>\n<p>In fact, some enterprising developers\u00a0<a href=\"https:\/\/learn.microsoft.com\/archive\/msdn-magazine\/2008\/june\/concurrent-affairs-simplified-apm-with-the-asyncenumerator\" rel=\"noopener noreferrer nofollow\">used iterators in this fashion for asynchronous programming<\/a>\u00a0before\u00a0<code>async<\/code>\/<code>await<\/code>\u00a0hit the scene.<\/p>\n<\/blockquote>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043b\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0447\u0442\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<h2>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 async \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 async \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c switch \u0432\u043d\u0443\u0442\u0440\u0438, \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u044d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b \u0442\u043e\u0442, \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u0443 (\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e) async \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u041f\u043e\u0441\u0442\u0430 \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"cs\">Stream source =GetSourceSomeHow();  Stream destination =GetDestinationSomeHow();    ... CopyStreamToStreamAsync(source, destination); ...<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0422\u0430\u0441\u043a, \u0438 \u0442\u0443\u0442 \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043d\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0436\u0434\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u0432 \u043d\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 await, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 await \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0440\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e await \u0438 \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e await \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043d\u043e\u0432\u0430 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d (\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c switch \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 case \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043a\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430 \u043c\u0435\u0436\u0434\u0443 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 await-\u0430\u043c\u0438). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c await \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u0430\u043a \u0438\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 yield return.<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d continuation-\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u041f\u043e\u0441\u0442\u0430. \u0422\u0430\u043a\u0438\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0448\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c switch. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 await-\u0430\u043c\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c switch \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p>\u041d\u043e \u043c\u044b \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0442\u043e \u0436\u0435 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e switch-\u043e\u043c? \u0418 \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u0433\u0434\u0435 \u0438 \u043a\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430?<\/p>\n<p>\u042f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0432\u043e\u0437\u044c\u043c\u0443\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u044e \u044d\u0442\u0443 \u0445\u0438\u0442\u0440\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0441 \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u0432\u0441\u0451-\u0442\u0430\u043a\u0438, \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u043a\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u041f\u043e\u0441\u0442\u0435, \u0438 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u0441\u044b\u043b\u0430\u044e\u0441\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u042f \u0445\u043e\u0447\u0443 \u043b\u0438\u0448\u044c \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0430\u0434\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 <strong>\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong>.<\/p>\n<p>\u041d\u0435 \u0437\u043d\u0430\u044e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e (\u044d\u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437\u0430), \u043d\u043e \u044f \u0431\u044b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430\u0434\u043e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u0434 \u0443\u0447\u0435\u0431\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 Task \u2013 MyTask. \u041d\u043e \u044d\u0442\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0440\u044f\u0434 \u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u0442\u0435\u0441\u044c \u0441 \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c MyTask \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u0430 MyTask, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043a\u0440\u0443\u0433\u0443 \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u043e\u0431\u0449\u0435\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u044f \u0432\u0430\u043c \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043a\u0440\u0443\u0433\u0443.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 MyTask \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434:<\/p>\n<pre><code class=\"cs\">static Task CopyStreamToStreamAsync(Stream source, Stream destination)    static Task IterateAsync(IEnumerable&lt;Task> tasks)<\/code><\/pre>\n<p>\u0433\u0434\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u0435\u043d \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <\/p>\n<pre><code class=\"cs\">[AsyncStateMachine(typeof(&lt;CopyStreamToStreamAsync>d__0))] public Task CopyStreamToStreamAsync(Stream source, Stream destination)<\/code><\/pre>\n<p>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b (\u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f\u00bb, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0442\u0435\u043a\u0443\u0449\u0430\u044f await \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430), \u0432\u043e\u0442 \u044d\u0442\u0438 \u0442\u0438\u043f\u044b:<\/p>\n<pre><code class=\"cs\">public struct MyTaskMethodBuilder  class MyThreadPool<\/code><\/pre>\n<p>\u0418 \u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u044d\u0442\u043e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u0430\u043a \u0438 \u043e\u0431\u0435\u0449\u0430\u043b:<\/p>\n<pre><code class=\"cs\">   static MyThreadPool()     {         for (int i = 0; i &lt; Environment.ProcessorCount; i++)         {             new Thread(() =>             {                 while (true)                 {                     (Action action, ExecutionContext? ec) = s_workItems.Take();                     if (ec is null)                     {                         action();                     }                     else                     {                         ExecutionContext.Run(ec, s => ((Action)s!)(), action);                     }                 }             })             { IsBackground = true }.UnsafeStart();         }     }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>action<\/code> \u044d\u0442\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u043d\u0430\u0448\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c switch, \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0448\u0430 \u0443\u0447\u0435\u0431\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 ThreadPool \u2013 MyThreadPool. <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430, \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0441\u0442\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u043c await \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cs\">private void Complete(Exception? error) {     lock (this)     {         if (_completed)         {             throw new InvalidOperationException(\"Already completed\");         }          _error = error;         _completed = true;          if (_continuation is not null)         {             ThreadPool.QueueUserWorkItem(_ =>             {                 if (_ec is not null)                 {                     ExecutionContext.Run(_ec, _ => _continuation(this), null);                 }                 else                 {                     _continuation(this);                 }             });         }     } }<\/code><\/pre>\n<p>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 MyThreadPool. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u0434 \u0443\u0447\u0435\u0431\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 Task \u2013 MyTask, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0441\u0442\u0430\u0442\u0438, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u0443\u0441\u043a\u0430\u043c\u0438, \u0447\u0442\u043e \u0442\u043e\u0436\u0435, \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0432\u0435\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u044f \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 MyTask. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u043a\u0441\u0442\u0430\u0442\u0438, \u0437\u0434\u0435\u0441\u044c \u043a\u0440\u0443\u0433 \u0437\u0430\u043c\u044b\u043a\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u043e\u0442\u0441\u044b\u043b\u0430\u044e \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u043a\u043b\u0430\u0441\u0441\u0430 MyTask, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0430\u043d\u0430\u043b\u0438\u0437.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044f, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043f\u043e\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0443 \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0437 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 : <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">How Async\/Await Really Works in C#<\/a>, \u0438 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u044f \u0438\u0437 \u043d\u0435\u0435 \u043f\u043e\u043d\u044f\u043b.<\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u043d\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u041d\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u044e\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b Async\/Await, \u043f\u0440\u0438\u0447\u0435\u043c \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u0430 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435, \u0440\u0430\u043d\u0435\u0435 \u041d\u0415-\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0442\u0435\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0442\u044c \u0435\u0435 \u0434\u0430\u0436\u0435 \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041d\u043e \u044f \u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0442\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c-\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u043c\u043e\u0439, \u0441\u0443\u0433\u0443\u0431\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c\u0438, \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c\u0438 \u0434\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0447\u0442\u043e \u0438\u0445 \u043d\u0438\u043a\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0443\u0436\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0446\u0435\u043d\u0438\u0442 \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0438 \u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0438\u0445. \u041c\u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0443\u0442\u044c \u0432\u0435\u0449\u0435\u0439.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u043d\u0430 \u0432\u0430\u0448\u0443 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u0421\u0451\u0440\u0433\u0438\u0439.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/784630\/\"> https:\/\/habr.com\/ru\/articles\/784630\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0440\u0438\u0441\u043a\u043d\u0443 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u041f\u043e\u0441\u0442\u0430: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">How Async\/Await Really Works in C#<\/a>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/782762\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u201c\u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434\u201d. \u0422\u0430\u043a\u0436\u0435, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e) <a href=\"https:\/\/habr.com\/ru\/articles\/784072\/\" rel=\"noopener noreferrer nofollow\">\u0441 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 SynchronizationContext<\/a> \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0440 \u044d\u0442\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430.<\/p>\n<p>\u042d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434. \u042d\u0442\u043e \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u041f\u043e\u0441\u0442\u0430 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f (\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u0438) \u043c\u043e\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u0435\u0445 \u043c\u044b\u0441\u043b\u0435\u0439 \u0438 \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0445\u043e\u0442\u0435\u043b \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0434\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 Stephen Toub.<\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u044f \u043f\u0438\u0448\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438 \u043a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0432\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e \u0442\u0435\u043c\u0435, \u0430 \u0432\u044b \u043e\u0434\u043e\u0431\u0440\u044f\u0435\u0442\u0435 \u0438\u043b\u0438 \u043a\u0440\u0438\u0442\u0438\u043a\u0443\u0435\u0442\u0435\/\u0443\u0442\u043e\u0447\u043d\u044f\u0435\u0442\u0435 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u0430\u043c\u044b\u043c \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0438 \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0440\u043e\u0434\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430 \u0435\u0449\u0435 \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u043d\u0443\u044e \u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0438\u0437 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0442\u044b \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0438\u043b\u0438 \u0442\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043d\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 Async\/Await \u0432 C#.<\/p>\n<hr\/>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 Async\/Await \u0432 C#. \u041d\u043e \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0441 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c:<\/p>\n<h2>\u0418\u0437\u0432\u0438\u043b\u0438\u0441\u0442\u044b\u0439 \u043f\u0443\u0442\u044c \u0432 \u043c\u0438\u0440 async \/ await<\/h2>\n<p>\u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435\u043c \u041f\u043e\u0441\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0430\u0432\u0442\u043e\u0440 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0443\u0436\u0435 \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0446\u0435\u043b\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u0438 \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 Async\/Await \u0432 C#. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0432 \u043a\u043e\u0434\u0435. \u041d\u043e \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0438\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f) \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\/\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b-\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 C#, \u043a\u0430\u043a \u0440\u0430\u0437 \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 (\u0445\u043e\u0442\u044f \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0445) \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c.<\/p>\n<p>\u041a\u0430\u043a \u043f\u0438\u0448\u0435\u0442 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435, <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/understanding-the-whys-whats-and-whens-of-valuetask\/\" rel=\"noopener noreferrer nofollow\">Understanding the Whys, Whats, and Whens of ValueTask<\/a> (\u0442\u0430\u043c, \u043a\u0441\u0442\u0430\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0438 \u043a\u0430\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445):<\/p>\n<blockquote>\n<p>This is, after all, how we write synchronous code (e.g. Result result = SomeOperation();), and it naturally translates to the world of async \/ await.<\/p>\n<\/blockquote>\n<p>\u041f\u043e \u043c\u043e\u0438\u043c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u043b \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0438\u0437\u0432\u0438\u043b\u0438\u0441\u0442\u044b\u0439 \u043f\u0443\u0442\u044c \u0432 &#171;\u043c\u0438\u0440 async\/await&#187;. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0440\u0435\u0448\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u043c\u044b \u043a\u0430\u043a-\u0442\u043e \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u044d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u044b \u0411\u0415\u0417 \u043d\u0430\u0448\u0435\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u041d\u043e \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043c\u044b \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043d\u0430\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u0442\u044c \u0443\u0441\u0438\u043b\u0438\u0435 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0441 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u043a\u0443\u0440\u0441\u0430 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0430\u0432\u0442\u043e\u0440. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0441\u044f \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0432 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0441\u043c\u0435\u043d\u0430 \u044d\u043a\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u0431\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0435 \u0438\u0437\u043d\u0443\u0442\u0440\u0438, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0423\u0416\u0415 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0432\u0441\u0435\u043e\u0431\u044a\u0435\u043c\u043b\u044e\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430, \u0432 \u043f\u0435\u0434\u0430\u0433\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043b\u044f\u0445:<\/p>\n<blockquote>\n<p> &#8230; is only being done in the name of pedagogy &#8230;<\/p>\n<p>&#8230; we\u2019ll do the pedagogical thing and just implement a simple version. &#8230;<\/p>\n<\/blockquote>\n<p>\u0418 \u043f\u0438\u0448\u0435\u043c, \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0438\u0434\u0435\u044f\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u0438 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u0431\u044b \u0438\u0437\u043d\u0443\u0442\u0440\u0438, \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044e \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u044f\u0434\u0440\u0430 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a .Net \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0437\u0430\u043c\u0435\u043d\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>class MyTask \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e(\u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e) \u043a\u043b\u0430\u0441\u0441\u0430 Task<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cs\">public void ContinueWith(Action&lt;MyTask> action) public void SetResult() => Complete(null); public void SetException(Exception error) => Complete(error); private void Complete(Exception? error)  static Task IterateAsync(IEnumerable&lt;Task> tasks) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 (\u0442\u0438\u043f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441): public struct MyTaskMethodBuilder \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 TaskMethodBuilder<\/p>\n<\/li>\n<li>\n<p>class MyThreadPool \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 ThreadPool<\/p>\n<\/li>\n<\/ul>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430<\/h2>\n<p>\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0430\u043a\u0443\u0440\u0441\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0435\u0445\u043d\u0438\u043a\u0438, \u2026 \u043d\u0430\u0437\u043e\u0432\u0438\u0442\u0435, \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e) \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430 \u043a\u0430\u0434\u0440\u043e\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u044f\u0435\u0442. \u041d\u043e \u0430\u0432\u0442\u043e\u0440 \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043d\u0430\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u041f\u043e\u0441\u0442\u0430:<\/p>\n<pre><code class=\"cs\">\/\/ Asynchronously copy all data from source to destination. public async Task CopyStreamToStreamAsync(Stream source, Stream destination) {     var buffer = new byte[0x1000];     int numRead;     while ((numRead = await source.ReadAsync(buffer, 0, buffer.Length)) != 0)     {         await destination.WriteAsync(buffer, 0, numRead);     } }<\/code><\/pre>\n<p>\u0418 \u044f, \u043d\u0430\u0432\u0435\u0440\u043d\u043e, \u0442\u043e\u0436\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044f\u0441\u043d\u043e \u0438\u0437\u044a\u044f\u0441\u043d\u044f\u044e\u0441\u044c \u043f\u043e\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043f\u0435\u0448\u0443 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442, \u0437\u0434\u0435\u0441\u044c, \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0447\u0442\u043e \u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442 \u0441 \u0442\u0430\u0432\u0442\u043e\u043b\u043e\u0433\u0438\u0435\u0439: \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0434\u0430 \u0438 \u043e\u0431\u044a\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u043d\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0432\u0438\u0434\u0438\u043c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0410\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u043c \u043a\u043e\u0434 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c (\u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438) \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0432 \u043e\u0431\u0449\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043d\u0435 \u0443\u0434\u043e\u0441\u0443\u0436\u0438\u043b\u0441\u044f \u0434\u0430\u0436\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0433\u0434\u0435-\u0442\u043e, \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430, \u0438\u043d\u0430\u0447\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 async \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430, \u0430 \u0432\u043e\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e! \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0434\u0430\u043b\u0435\u0435, \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442, \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043b\u044e\u0431\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0443\u044e async (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e) \u0438 \u043c\u044b, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0442\u043e\u0436\u0435 \u0434\u043e\u0431\u0435\u0440\u0435\u043c\u0441\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">How Async\/Await Really Works in C#<\/a> \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 async, \u0435\u0441\u043b\u0438 \u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a \u043e\u0431\u044a\u0435\u043c\u0443 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h2>\u041a\u0430\u043a C# \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441\u043f\u0430\u0441\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043a\u043e\u043b\u0431\u0435\u043a\u043e\u0432, \u043d\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/h2>\n<p>\u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f: <strong>C# Iterators to the Rescue.<\/strong><\/p>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u043a: C# \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c (\u0441\u043f\u0430\u0441\u043b\u0438 \u043d\u0430\u0441). \u041f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u0438\u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u043f\u0430\u0441\u0430\u044e\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c callbacks (\u043a\u043e\u043b\u0431\u0435\u043a\u0438) \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/782762\/\" rel=\"noopener noreferrer nofollow\">Async\/Await \u0432 C#. \u0423\u0440\u043e\u043a\u0438 \u043f\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e<\/a> \u043c\u044b \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u0412\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f Async\/Await\u00bb, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u00ab\u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 yield return \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 IEnumerable&lt;> \u0441\u043f\u0438\u0441\u043a\u0430\u00bb \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 Async\/Await.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 Async, \u0430 \u043a\u0430\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043b\u043e\u0433\u0438\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u044b \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u043c\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0442\u0435 \u0438\u0434\u0435\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u0441\u0442\u0430 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0434\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0438, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u0410\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0441\u0442\u0438\u043b\u0435 \u00abyield return \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 IEnumerable&lt;> \u0441\u043f\u0438\u0441\u043a\u0430\u00bb:<\/p>\n<pre><code class=\"cs\">    static IEnumerable&lt;Task> Impl(Stream source, Stream destination)     {         var buffer = new byte[0x1000];         while (true)         {             Task&lt;int> read = source.ReadAsync(buffer, 0, buffer.Length);             yield return read;             int numRead = read.Result;             if (numRead &lt;= 0)             {                 break;             }              Task write = destination.WriteAsync(buffer, 0, numRead);             yield return write;             write.Wait();         }     }<\/code><\/pre>\n<p>\u042f \u0434\u0443\u043c\u0430\u044e, \u0438\u0434\u0435\u044f \u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u0430, \u043d\u043e \u044f \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u044e \u0435\u0435 \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439. \u0421\u0443\u0442\u044c \u0438\u0434\u0435\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e yield return \u0438 \u0434\u0430\u043b\u0435\u0435 \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e yield return \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 case X-STATE: \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 switch \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0442\u0435\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0442\u043e\u0436\u0435 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u043b, \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">static Task CopyStreamToStreamAsync(Stream source, Stream destination) {     return IterateAsync(Impl(source,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-364598","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=364598"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364598\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}