{"id":367853,"date":"2024-05-21T03:29:58","date_gmt":"2024-05-21T03:29:58","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=367853"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=367853","title":{"rendered":"<span>\u041a\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 Async\/Await \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 C#. \u0427\u0430\u0441\u0442\u044c 6. \u0410\u043d\u0430\u043b\u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/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>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b Stephen Toub-\u0430: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">\u00abHow Async\/Await Really Works in C#\u00bb<\/a>. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437, \u0432 \u0441\u043b\u0435\u0434 \u0437\u0430 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 C# \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u044d\u0442\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439-\u043f\u043e\u043d\u044f\u0442\u0438\u0439-\u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a: \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0431\u043e\u043a\u0441\u0438\u043d\u0433, \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u0430, \u0441\u0442\u0435\u043a, \u043f\u043e\u0442\u043e\u043a\u0438, \u2026 \u042d\u0442\u0430 6-\u044f \u0447\u0430\u0441\u0442\u044c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u041a\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 Async\/Await \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 (\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f) \u0432 C#\u00bb<\/p>\n<p>\u0422\u0430\u043c, \u0433\u0434\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0446\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0434\u043e\u0441\u043b\u043e\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c), \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e <em><u>\u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u043c \u043a\u0443\u0440\u0441\u0438\u0432\u043e\u043c<\/u><\/em>.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <a href=\"https:\/\/habr.com\/ru\/articles\/732738\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c<\/a>.<\/p>\n<hr\/>\n<p>\u0418\u0442\u0430\u043a, \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434:   <\/p>\n<pre><code class=\"cs\">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>\u041e\u043d \u043f\u043e\u044f\u0441\u043d\u044f\u0435\u0442 \u043d\u0430\u043c \u0447\u0442\u043e <em><u>\u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u043e\u043c, \u00ab\u0433\u043b\u043e\u0442\u043a\u043e\u043c \u0441\u0432\u0435\u0436\u0435\u0433\u043e \u0432\u043e\u0437\u0434\u0443\u0445\u0430\u00bb \u0432\u044b\u0440\u0430\u0436\u0430\u044f\u0441\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u043e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u043c\u0438 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/u><\/em><\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">public void CopyStreamToStream(Stream source, Stream destination) {     var buffer = new byte[0x1000];     int numRead;     while ((numRead = source.Read(buffer, 0, buffer.Length)) != 0)     {         destination.Write(buffer, 0, numRead);     } }<\/code><\/pre>\n<p><em><u>\u0412\u0441\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438(\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043b\u0438) \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c async \u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 void \u043d\u0430 Task, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439: ReadAsync, WriteAsync \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 Read, Write, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a \u044d\u0442\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u0430\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 await. \u0418 \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u044f\u0434\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u044f \u0442\u043e, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043a\u043e\u0434. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c.<\/u><\/em><\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u0440\u043c\u0438\u043d <em><u>&#171;\u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430&#187;<\/u><\/em>. \u042d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0418\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 MoveNext() \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. \u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u0443\u0434\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u0432 \u0442\u043e\u0439 \u0436\u0435 \u043c\u0430\u043d\u0435\u0440\u0435.<\/p>\n<p><em><u>\u041c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u0447\u0442\u043e, \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0434\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0434 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0434\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (<\/u><\/em><code>public Task CopyStreamToStreamAsync(Stream source, Stream destination)<\/code><em><u>), \u043d\u043e \u0442\u0435\u043b\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0438\u043d\u044b\u043c:<\/u><\/em><\/p>\n<pre><code class=\"cs\">[AsyncStateMachine(typeof(&lt;CopyStreamToStreamAsync>d__0))] public Task CopyStreamToStreamAsync(Stream source, Stream destination) {     &lt;CopyStreamToStreamAsync>d__0 stateMachine = default;     stateMachine.&lt;>t__builder = AsyncTaskMethodBuilder.Create();     stateMachine.source = source;     stateMachine.destination = destination;     stateMachine.&lt;>1__state = -1;     stateMachine.&lt;>t__builder.Start(ref stateMachine);     return stateMachine.&lt;>t__builder.Task; }  private struct &lt;CopyStreamToStreamAsync>d__0 : IAsyncStateMachine {     public int &lt;>1__state;     public AsyncTaskMethodBuilder &lt;>t__builder;     public Stream source;     public Stream destination;     private byte[] &lt;buffer>5__2;     private TaskAwaiter &lt;>u__1;     private TaskAwaiter&lt;int> &lt;>u__2;      ... }<\/code><\/pre>\n<p><em><u>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, &#8212; \u044d\u0442\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 async. \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 async \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u0430; \u043a\u0430\u043a \u0438 unsafe. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u0430, \u0432\u044b \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430<\/u><\/em> (\u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438)<em><u>, \u0430 \u043d\u0435 \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 async\/await \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c.<\/u><\/em><\/p>\n<p><em><u>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &lt;CopyStreamToStreamAsync>d__0, \u0438 \u043e\u043d \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u0443\u043b\u044f\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u0441\u0442\u0435\u043a\u0435. \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043a\u0438\u043d\u0435\u0442 \u0441\u0442\u0435\u043a. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u043e \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438), \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0430-\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0432\u0438\u0441\u043d\u0435\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 await, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0432\u0438\u0441\u043d\u0435\u0442 \u043d\u0430 \u0447\u0435\u043c-\u0442\u043e \u0447\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/u><\/em><\/p>\n<p><em><u>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u044e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0435 \u201c\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435\u201d \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0437\u0432\u043b\u0435\u043a \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 MoveNext. \u042d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 IEnumerable&lt;T>\/IEnumerator&lt;T>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 <\/u><\/em><a href=\"https:\/\/habr.com\/ru\/articles\/790944\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/em><\/a><em><u>. (\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u0432\u0437\u044f\u0442 \u0438\u0437 \u0441\u0431\u043e\u0440\u043a\u0438 release; \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u0441\u0431\u043e\u0440\u043a\u0430\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 C# \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u0442\u0438\u043f\u044b \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435).<\/u><\/em><\/p>\n<p><em><u>\u041f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432\u044b\u0437\u043e\u0432 AsyncTaskMethodBuilder.Create(). \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430\u0445-Tasks, \u044f\u0437\u044b\u043a C# \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 (\u0442\u0438\u043f\u043e\u0432 \u201c\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445-\u0437\u0430\u0434\u0430\u0447\u0435\u201d) \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434<\/u><\/em><\/p>\n<pre><code class=\"cs\">public async MyTask CopyStreamToStreamAsync<\/code><\/pre>\n<p><em><u>\u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c MyTask, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u201cbuilder\u201d \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0441 \u0442\u0438\u043f\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 AsyncMethodBuilder:<\/u><\/em><\/p>\n<pre><code class=\"cs\">[AsyncMethodBuilder(typeof(MyTaskMethodBuilder))] public class MyTask {     ... }  public struct MyTaskMethodBuilder {     public static MyTaskMethodBuilder Create() { ... }      public void Start&lt;TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { ... }     public void SetStateMachine(IAsyncStateMachine stateMachine) { ... }      public void SetResult() { ... }     public void SetException(Exception exception) { ... }      public void AwaitOnCompleted&lt;TAwaiter, TStateMachine>(         ref TAwaiter awaiter, ref TStateMachine stateMachine)         where TAwaiter : INotifyCompletion         where TStateMachine : IAsyncStateMachine { ... }     public void AwaitUnsafeOnCompleted&lt;TAwaiter, TStateMachine>(         ref TAwaiter awaiter, ref TStateMachine stateMachine)         where TAwaiter : ICriticalNotifyCompletion         where TStateMachine : IAsyncStateMachine { ... }      public MyTask Task { get { ... } } }<\/code><\/pre>\n<p><em><u>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0442\u0430\u043a\u043e\u0439 \u201cbuilder\u201d \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/u><\/em>(-\u0444\u0430\u0431\u0440\u0438\u043a\u0430, \u0441\u043c\u043e\u0442\u0440\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u00bb) <em><u>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 (\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Task), \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0435\u0433\u043e \u043b\u0438\u0431\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (SetResult), \u043b\u0438\u0431\u043e \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c (SetException), \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439<\/u><\/em> ( \u0441\u043c\u043e\u0442\u0440\u0438 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u00bb \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/790944\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a> \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043c\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u00abasync\/await \u0432 C#\u00bb \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0447\u0442\u043e \u201cbuilder\u201d \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0418 \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0430\u043b\u0435\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430  \u201cbuilder\u201d)<\/p>\n<p><em><u>\u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c \u0441 await, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b<\/u><\/em> <em><u>(AwaitOnCompleted\/AwaitUnsafeOnCompleted). \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 System.Threading.Tasks.Task &#8212; \u0442\u0438\u043f\u0430, \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0432\u044f\u0437\u0430\u043d \u0441 AsyncTaskMethodBuilder. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u0430 \u0441\u0432\u044f\u0437\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 [AsyncMethodBuilder(&#8230;)], \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u043a \u0442\u0438\u043f\u0443, \u043d\u043e Task \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0432 C# \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0430\u043a\u043e\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <\/u><\/em>(\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u0435\u043d \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Task, \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438)<em><u>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 Create, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, AsyncTaskMethodBuilder \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438).<\/u><\/em><\/p>\n<p><em><u>\u0417\u0430\u0442\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 MoveNext, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. MoveNext \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0432\u0441\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 MoveNext, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u043c\u043e\u0433 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0438\u0445 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 MoveNext. \u0421\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c -1, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f MoveNext \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e -1, \u043c\u044b \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/u><\/em><\/p>\n<p><em><u>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u0430\u044f \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f, \u043d\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430: \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Start \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0442\u0438\u043f\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e* async \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e MoveNext \u043d\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0435. \u041c\u0435\u0442\u043e\u0434 Start \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e:<\/u><\/em><\/p>\n<pre><code class=\"cs\">public void Start&lt;TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {     stateMachine.MoveNext(); }<\/code><\/pre>\n<p>*\u0432\u0430\u0436\u043d\u043e\u0435 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435: \u043d\u0430\u0448\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (<em><u>async \u043c\u0435\u0442\u043e\u0434<\/u><\/em>)<\/p>\n<pre><code class=\"cs\">public async Task CopyStreamToStreamAsync(Stream source, Stream destination)<\/code><\/pre>\n<p>\u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u0430\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u043d\u0430\u0448\u0435\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u00ab\u0436\u0438\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c\u00bb \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e (\u0438\u043b\u0438 \u043f\u0441\u0435\u0432\u0434\u043e-\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e) \u043a\u043e\u0434\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u0432\u0430\u043b \u043d\u0430\u0448\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0435. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u043a \u0431\u044b \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043b \u043a\u0430\u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 MoveNext. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0441\u043c\u043e\u0442\u0440\u0438 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/790944\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a> \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043c\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u00abasync\/await \u0432 C#\u00bb.<\/p>\n<p><em><u>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b\u0437\u043e\u0432 <\/u><\/em><\/p>\n<p>StateMachine.&lt;>t__builder.Start(ref state Machine); <\/p>\n<p><em><u>\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 stateMachine.MoveNext(). \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 MoveNext \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e? \u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u0435\u043d Start? \u041e\u0442\u0432\u0435\u0442 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e Start \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043b\u043e\u0433\u0438\u043a\u0438, \u0447\u0435\u043c \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0437\u0434\u0435\u0441\u044c. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u044d\u043a\u0441\u043a\u0443\u0440\u0441 \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 ExecutionContext.<\/u><\/em><\/p>\n<h2>ExecutionContext -\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0422\u0443\u0442 \u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0436\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u0438\u0434\u0435\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 C# \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u0430\u043a \u044f \u0438\u0445 \u043f\u043e\u043d\u044f\u043b (\u0430 \u043d\u0435 \u043a\u0430\u043a \u0438\u0445 \u0438\u0437\u043b\u043e\u0436\u0438\u043b \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430).<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u043d\u0430\u0434\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<pre><code class=\"cs\">public async Task CopyStreamToStreamAsync(Stream source, Stream destination)<\/code><\/pre>\n<p>\u0438 \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u043f\u0430\u0434\u0435\u0442 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043a\u0443\u0441\u043a\u043e\u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em><u>MoveNext<\/u><\/em> \u0431\u0443\u0434\u0443\u0442 \u043d\u0443\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0435\u0449\u0435 \u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0438 \u0432\u044b\u0437\u043e\u0432\u044b <em><u>MoveNext<\/u><\/em> \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043d\u0430\u0448\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u043f\u0430\u043b\u0430 \u0431\u044b \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441), \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043d\u0435\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0441\u044b\u043b\u043e\u043a, \u0438 \u0435\u0435 \u0431\u044b \u0443\u0442\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430, \u0438 \u043e\u043d \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0433 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c (\u043b\u043e\u0433\u0438\u043a\u0430), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 (\u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c), \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0412\u0421\u0415\u0425 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439) \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441 \u0442\u0435\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044d\u0442\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d\u0430-\u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430. \u0421\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u2013 <em><u>ExecutionContext.<\/u><\/em><\/p>\n<p>\u0410\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u044e, \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e:   <\/p>\n<pre><code class=\"cs\">using System.Collections.Concurrent;  var number = new AsyncLocal&lt;int>();  number.Value = 42; MyThreadPool.QueueUserWorkItem(() => Console.WriteLine(number.Value)); number.Value = 0;  Console.ReadLine();  class MyThreadPool {     private static readonly BlockingCollection&lt;(Action, ExecutionContext?)> s_workItems = new();      public static void QueueUserWorkItem(Action workItem)     {         s_workItems.Add((workItem, ExecutionContext.Capture()));     }      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>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043e\u043d \u0434\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p><em><u>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f, \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u0435, \u0447\u0442\u043e \u044f \u0432\u044b\u0437\u0432\u0430\u043b UnsafeStart \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 MyThreadPool. \u0417\u0430\u043f\u0443\u0441\u043a \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 ExecutionContext. \u041d\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 ExecutionContext.Capture \u0434\u043b\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0435\u0433\u043e \u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 ThreadStart \u043f\u043e\u0442\u043e\u043a\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435 \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044f \u043d\u0435 \u0445\u043e\u0442\u0435\u043b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043a\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 ExecutionContext, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 (\u044d\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044e ExecutionContext \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e\u0439), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043c\u0435\u0442\u043e\u0434 UnsafeStart. \u0421\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 Unsafe, \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 Unsafe, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0442 ExecutionContext, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Thread.Start \u0438 Thread.UnsafeStart \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Start \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 ExecutionContext, UnsafeStart \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442.<\/u><\/em><\/p>\n<h2>\u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Start<\/h2>\n<p>\u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0432 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">public void Start&lt;TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {     ExecutionContext previous = Thread.CurrentThread._executionContext; \/\/ [ThreadStatic] field     try     {         stateMachine.MoveNext();     }     finally     {         ExecutionContext.Restore(previous); \/\/ internal helper     } }<\/code><\/pre>\n<p>\u0421\u0443\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e MoveNext \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0435\u0441\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043d\u0435\u0448\u0442\u0430\u0442\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430\u0434\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c. \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435, \u043e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0435\u0433\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043c.<\/p>\n<h2>\u0414\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f MoveNext<\/h2>\n<p><em><u>\u0418\u0442\u0430\u043a, \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f Start \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0438 \u043e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 MoveNext. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 MoveNext? \u042d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043d\u043e \u0441 \u0446\u0435\u043b\u044b\u043c \u0440\u044f\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u043c. \u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043d\u043e \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 try:<\/u><\/em><\/p>\n<pre><code class=\"cs\">private void MoveNext() {     try     {         ... \/\/ all of the code from the CopyStreamToStreamAsync method body, but not exactly as it was written     }     catch (Exception exception)     {         &lt;>1__state = -2;         &lt;buffer>5__2 = null;         &lt;>t__builder.SetException(exception);         return;     }      &lt;>1__state = -2;     &lt;buffer>5__2 = null;     &lt;>t__builder.SetResult(); }<\/code><\/pre>\n<p><em><u>\u041a\u0430\u043a\u0443\u044e \u0431\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b \u043c\u0435\u0442\u043e\u0434 MoveNext, \u043e\u043d \u043d\u0435\u0441\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u043a async Task, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0442\u0435\u043b\u043e \u0431\u043b\u043e\u043a\u0430 try \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u0430 \u0441 \u044d\u0442\u0438\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c. \u0418 \u0435\u0441\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f (\u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434), \u043e\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u0412 \u043b\u044e\u0431\u043e\u043c \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443 \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. (\u042f \u0438\u043d\u043e\u0433\u0434\u0430 \u0441\u043b\u044b\u0448\u0443, \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0437\u0438\u0440\u0443\u044e\u0442, \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u043e \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0438 \u0442\u0435\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435&#8230; \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e, \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u041b\u044e\u0431\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0433\u0434\u0435 \u043e\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432\u044b\u0434\u0430\u043b \u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u043f\u0430\u0434\u0435\u0442 \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0431\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430, \u0430 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u0432 \u0437\u0430\u0434\u0430\u0447\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.)<\/u><\/em><\/p>\n<p><em><u>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 builder(\u043a\u043b\u0430\u0441\u0441-\u043e\u0431\u044a\u0435\u043a\u0442), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b SetException \u0438 SetResult, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f builder, \u043a\u043e\u0442\u043e\u043e\u0440\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 async \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0443\u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u044b\u0432\u0430-\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f (\u0441\u043a\u043e\u0440\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0438 \u0433\u0434\u0435), \u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0437\u043e\u0432 SetException\/SetResult \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443 builder-\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0440\u0430\u043d\u0435\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442, \u2014 \u044d\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 Task builder-\u0430 (<\/u>\u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e Task, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437\u0432\u0438\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u0430 \u044d\u0442\u043e<u>):<\/u><\/em><\/p>\n<pre><code class=\"cs\">public Task CopyStreamToStreamAsync(Stream source, Stream destination) {     ...     return stateMachine.&lt;>t__builder.Task; }<\/code><\/pre>\n<p><em><u>\u041d\u0430\u0448 builder \u0437\u043d\u0430\u0435\u0442, \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e, \u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430, \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0435. \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f \u0438 \u0443 builder \u0435\u0449\u0435 \u043d\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0437\u0434\u0435\u0441\u044c. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Task.CompletedTask \u0432\u043c\u0435\u0441\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u043b\u044e\u0431\u043e\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a Task&lt;TResult> builder \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Task.FromResult&lt;TResult>(TResult result).<\/u><\/em><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447 (Task), \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 C# \u0443\u0431\u0440\u0430\u043b\u0438 \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0438 \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u0435\u043a\u0442 builder \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043c\u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/779510\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b SOLID<\/a>.<\/p>\n<p><em><u>\u041e\u0431\u044a\u0435\u043a\u0442 builder \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u0441\u043e\u0447\u0442\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442. <\/u><\/em><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u043c\u0438 \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u0447 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u043c\u0438 \u043d\u0430 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043d\u043e\u0439 async \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0435 \u0435\u0435. \u0422\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0430\u0434\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u044d\u0442\u043e \u0443\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u0441 \u0447\u0443\u0442\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043b\u0438\u043d\u0438\u0438 \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u044d\u0442\u0438\u043c \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p><em><u>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u0430\u0441\u043f\u0435\u043a\u0442\u0430\u043c\u0438 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0431\u043b\u043e\u043a\u0430 try \u0432 MoveNext:<\/u><\/em><\/p>\n<pre><code class=\"cs\">private void MoveNext() {     try     {         int num = &lt;>1__state;          TaskAwaiter&lt;int> awaiter;         if (num != 0)         {             if (num != 1)             {                 &lt;buffer>5__2 = new byte[4096];                 goto IL_008b;             }              awaiter = &lt;>u__2;             &lt;>u__2 = default(TaskAwaiter&lt;int>);             num = (&lt;>1__state = -1);             goto IL_00f0;         }          TaskAwaiter awaiter2 = &lt;>u__1;         &lt;>u__1 = default(TaskAwaiter);         num = (&lt;>1__state = -1);         IL_0084:         awaiter2.GetResult();          IL_008b:         awaiter = source.ReadAsync(&lt;buffer>5__2, 0, &lt;buffer>5__2.Length).GetAwaiter();         if (!awaiter.IsCompleted)         {             num = (&lt;>1__state = 1);             &lt;>u__2 = awaiter;             &lt;>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);             return;         }         IL_00f0:         int result;         if ((result = awaiter.GetResult()) != 0)         {             awaiter2 = destination.WriteAsync(&lt;buffer>5__2, 0, result).GetAwaiter();             if (!awaiter2.IsCompleted)             {                 num = (&lt;>1__state = 0);                 &lt;>u__1 = awaiter2;                 &lt;>t__builder.AwaitUnsafeOnCompleted(ref awaiter2, ref this);                 return;             }             goto IL_0084;         }     }     catch (Exception exception)     {         &lt;>1__state = -2;         &lt;buffer>5__2 = null;         &lt;>t__builder.SetException(exception);         return;     }      &lt;>1__state = -2;     &lt;buffer>5__2 = null;     &lt;>t__builder.SetResult(); }<\/code><\/pre>\n<p>\u0410\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0440\u0443\u0447\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0442\u043e\u0433\u043e \u0436\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u043f\u0440\u0438\u0432\u0435\u043b \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/781058\/\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f APM, \u0442\u0443\u0442 \u043c\u043e\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f<\/a>, \u0442\u043e\u043b\u044c\u043a\u043e <em><u>\u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430 \u043d\u0430\u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439\u00bb \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/u><\/em>!<\/p>\n<p><em><u>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c -1 \u0432 \u0442\u043e\u0447\u043a\u0435 \u0432\u0445\u043e\u0434\u0430. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u0445\u043e\u0434\u0438\u043c \u0432 MoveNext, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 num) \u043d\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0438 0, \u043d\u0438 1, \u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u043c\u0435\u0442\u043a\u0435 IL_008b, \u0433\u0434\u0435 \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 stream.ReadAsync. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 MoveNext \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 Start \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 CopyStreamToStreamAsync, \u0438 \u043e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0435\u0449\u0435 \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u041d\u043e \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f\u2026<\/u><\/em><\/p>\n<p><em><u>\u041c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c Stream.ReadAsync \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e Task&lt;int>. \u0427\u0442\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u043b\u0438 \u043e\u043d\u043e \u043c\u043e\u0433\u043b\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u043d\u043e \u0442\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u043e \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e, \u0438\u043b\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u043d\u043e \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c. \u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u044d\u0442\u043e\u0433\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c Task&lt;int>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u044d\u0442\u0443 Task&lt;int>, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435: \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 Task&lt;int> \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 (\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u044b\u043b\u0430 \u043b\u0438 \u043e\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0438\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043a \u0442\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c), \u0442\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u2026 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b, \u0435\u0441\u043b\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0438 \u0441\u0435\u0439\u0447\u0430\u0441. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 Task&lt;int> \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043a Task&lt;int>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 Task&lt;int> \u201c\u0432\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438?\u201d \u041e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a \u0437\u0430\u0434\u0430\u0447\u0435, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441?<\/u><\/em><\/p>\n<p><em><u>\u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c, \u0435\u0441\u043b\u0438 \u0431\u044b \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c await \u0432 C#, \u0431\u044b\u043b\u0430 \u0431\u044b System.Threading.Tasks.Task. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c, \u0435\u0441\u043b\u0438 \u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 C# \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0437\u043d\u0430\u0442\u044c \u043e \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u043c \u0442\u0438\u043f\u0435, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c await. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e C# \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0432 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445: \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d API (\u0448\u0430\u0431\u043b\u043e\u043d \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438). \u041a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u201cawaiter\u201d (\u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 foreach \u0432\u0441\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u201cenumerable\u201d). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u0438\u043f MyTask, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f:<\/u><\/em><\/p>\n<pre><code class=\"cs\">class MyTask {     ...     public MyTaskAwaiter GetAwaiter() => new MyTaskAwaiter { _task = this };      public struct MyTaskAwaiter : ICriticalNotifyCompletion     {         internal MyTask _task;          public bool IsCompleted => _task._completed;         public void OnCompleted(Action continuation) => _task.ContinueWith(_ => continuation());         public void UnsafeOnCompleted(Action continuation) => _task.ContinueWith(_ => continuation());         public void GetResult() => _task.Wait();     } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 (a pattern of APIs) \u043a\u0430\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0442\u0430\u043a\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438\u0437 C# \u043a\u0430\u043a: await, foreach, \u044f \u043c\u043e\u0433\u0443 \u0435\u0449\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c using, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u043e\u043d\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043a \u0442\u0438\u043f\u0443 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u043b\u043e \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0434\u0430 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0434\u0430 \u0438 \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e \u043d\u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e. \u0418 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430, \u043f\u043e \u043c\u043e\u0435\u043c\u0443, \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u044e\u0449\u0438\u0439-\u043f\u043e\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442 \u0437\u0434\u0435\u0441\u044c, \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u0437\u0430 \u043d\u0438\u043c, \u0445\u043e\u0442\u044f \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043b\u0438\u0436\u0435 \u043a \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 (\u044f \u0433\u0434\u0435-\u0442\u043e \u0441\u043b\u044b\u0448\u0430\u043b), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0431\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0442\u0435\u043a\u0441\u0442\u0443.<\/p>\n<p><em><u>\u0422\u0438\u043f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c awaited, \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 GetAwaiter(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u0443 Task. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e IsCompleted, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 IsCompleted, \u0431\u044b\u043b\u0430 \u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0418 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440: \u0432 IL_008b \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0439 \u0438\u0437 ReadAsync, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f GetAwaiter, \u0430 \u0437\u0430\u0442\u0435\u043c IsCompleted \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0443 \u044d\u0442\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 struct awaiter. \u0415\u0441\u043b\u0438 IsCompleted \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 true, \u0442\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a IL_00f0, \u0433\u0434\u0435 \u043a\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u043b\u0435\u043d awaiter-\u0430: GetResult(). \u0415\u0441\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f GetResult() \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0437 await \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435; \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f GetResult() \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u0438\u043c\u0435\u0435\u0442\u0441\u044f. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 ReadAsync, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0432\u0435\u043d 0, \u0442\u043e \u043c\u044b \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043a\u043e\u043d\u0446\u0443 \u043c\u0435\u0442\u043e\u0434\u0430, \u0433\u0434\u0435 \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 SetResult, \u0438 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e.<\/u><\/em><\/p>\n<p><em><u>\u0415\u0449\u0435 \u0440\u0430\u0437 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 IsCompleted \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 false. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0446\u0438\u043a\u043b, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 APM, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0433\u0434\u0430 CompletedSynchronously \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true \u0442\u043e\u0433\u0434\u0430 \u0442\u043e\u0442, \u043a\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u043b \u043c\u0435\u0442\u043e\u0434 Begin, \u0430 \u043d\u0435 callback, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 IsCompleted \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 false, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c await. \u0410 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0438\u0437 MoveNext, \u0438 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0447\u0430\u0441\u0442\u044c\u044e Start, \u0438 \u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432 \u0432\u044b\u0437\u043e\u0432\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043a \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 (\u043e\u0442\u043c\u0435\u0447\u0430\u044f, \u0447\u0442\u043e \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0439 \u0432 \u0441\u0442\u0435\u043a(\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438), \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 APM, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 APM \u0435\u0441\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a IsCompleted \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 false, \u043d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0438\u0437 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f \u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u0437\u0430\u0434\u0430\u0447\u0438; \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434, \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/u><\/em><\/p>\n<p><em><u>\u041e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e, \u0447\u0442\u043e awaiter \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435? \u042d\u0442\u043e \u0438\u043c\u0435\u043b\u043e \u0431\u044b \u0441\u043c\u044b\u0441\u043b; \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0441\u0430\u043c\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 ContinueWith \u0438 \u0442.\u0434. &#8230; \u0420\u0430\u0437\u0432\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d GetAwaiter \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c TaskAwaiter, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043d\u0430\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435? \u0418 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0428\u0430\u0431\u043b\u043e\u043d awaiter \u0442\u0440\u0435\u0431\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b awaiter \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 INotifyCompletion, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 void OnCompleted(Action continuation). \u041e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0439 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ICriticalNotifyCompletion, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 INotifyCompletion \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 void UnsafeOnCompleted(Action continuation). \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044e ExecutionContext, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0432 \u0447\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438: \u043e\u0431\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u043d\u043e, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a OnCompleted \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c ExecutionContext, \u0434\u043b\u044f UnsafeOnCompleted \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0437\u0434\u0435\u0441\u044c, INotifyCompletion.OnCompleted \u0438 ICriticalNotifyCompletion.UnsafeOnCompleted, \u0432 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0430\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u0434\u0443, \u0438\u043b\u0438 CAS. CAS \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 .NET Core, \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d \u0432 .NET Framework, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0435\u0440\u043d\u0435\u0442\u0435\u0441\u044c \u043a \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f CAS \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c ExecutionContext, \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u201c\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u201d, \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442 ExecutionContext, \u0431\u044b\u043b \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u201c\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439\u201d. \u0422\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0438 \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u044b \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 [SecurityCritical], \u0438 \u043a\u043e\u0434 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 [SecurityCritical]. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 OnCompleted, \u043f\u0440\u0438\u0447\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c UnsafeOnCompleted, \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d, \u043d\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442 OnCompleted \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0441\u044f \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 awaiter \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 ExecutionContext \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0447\u043a\u0438 \u0441 await-\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0431\u044b awaiter \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b \u044d\u0442\u043e, \u044d\u0442\u043e \u0441\u0442\u0430\u043b\u043e \u0431\u044b \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0439 \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439.<\/u><\/em><\/p>\n<p><em><u>\u0425\u043e\u0440\u043e\u0448\u043e, \u0438\u0442\u0430\u043a, awaiter \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0433 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438: \u043a\u0430\u043a\u0438\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435? \u0418 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0441 \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043e? \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0435\u043a\u0435, \u0438 \u0432\u044b\u0437\u043e\u0432 MoveNext, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0441\u044f, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u044d\u0442\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0443 \u043d\u0430\u0441 \u043e\u043f\u044f\u0442\u044c \u0431\u044b\u043b\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0436\u0438\u0442\u044c \u0432 \u0441\u0442\u0435\u043a\u0435; \u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0445\u0438\u043f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0435\u043a \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439, \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0439 \u044d\u0442\u0438\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c. \u0418 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 MoveNext \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u0445\u0438\u043f\u0435.<\/u><\/em><\/p>\n<p><em><u>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, ExecutionContext \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0434\u0435\u0441\u044c. \u0421\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430 \u0434\u043e\u043b\u0436\u0435\u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043b\u044e\u0431\u044b\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 ExecutionContext, \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u044b \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u044d\u0442\u043e\u0442 ExecutionContext. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430 MoveNext \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 MoveNext \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b (\u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0435 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430) \u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442 (\u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u043a \u043d\u043e\u0432\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0442\u0430\u043d\u0435\u0446, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0438\u0437 \u0441\u0442\u0435\u043a\u0430 \u0432 \u0445\u0438\u043f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043d\u043e \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0445\u0438\u043f\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 MoveNext, \u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0438 \u043f\u0440\u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/u><\/em><\/p>\n<p><em><u>\u0412 \u044d\u0442\u043e\u043c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043b\u043e\u0433\u0438\u043a\u0438, \u0447\u0435\u043c \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b, \u0447\u0442\u043e\u0431\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u2026 \u0431\u044b\u043b\u043e \u0431\u044b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0435\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0431\u044b\u043b\u0430 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0432\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u0432 \u0441\u0431\u043e\u0440\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 builder (\u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043f\u043e\u0447\u0435\u043c\u0443, \u043f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043f\u0443\u043b\u0438\u043d\u0433\u0435). \u0418 \u0432-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0438 \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0440\u0430\u043d\u0435\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u042d\u0442\u043e \u043d\u0435 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u0435! \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u044d\u0442\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0431\u044b\u043b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432 .NET Core 2.1, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u0442\u0430\u043b\u0430 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 .NET Framework. \u041c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0432 .NET Framework, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432 .NET Core.<\/u><\/em><\/p>\n<p><em><u>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0432 \u043a\u043e\u0434\u0435, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c C#, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044e:<\/u><\/em><\/p>\n<pre><code class=\"cs\">if (!awaiter.IsCompleted) \/\/ we need to suspend when IsCompleted is false {     &lt;>1__state = 1;     &lt;>u__2 = awaiter;     &lt;>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);     return; }<\/code><\/pre>\n<p><em><u>\u041c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u043e\u043b\u0435 state \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043f\u0440\u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 awaiter \u0432 \u043f\u043e\u043b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 GetResult \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0418 \u0437\u0430\u0442\u0435\u043c, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 MoveNext, \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c, \u044d\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c &lt;>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this), \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0443 builder-\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f \u043a awaiter-\u0443 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. (\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 AwaitUnsafeOnCompleted builder-\u0430, \u0430 \u043d\u0435 AwaitOnCompleted builder-\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e awaiter \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 ICriticalNotifyCompletion; \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 ExecutionContext, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b awaiter \u0442\u043e\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b&#8230; \u043a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c\u0438.)<\/u><\/em><\/p>\n<p><em><u>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 AwaitUnsafeOnCompleted \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0437\u0434\u0435\u0441\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u043f\u0438\u0448\u0443, <\/u><\/em><a href=\"https:\/\/referencesource.microsoft.com\/#mscorlib\/system\/runtime\/compilerservices\/AsyncMethodBuilder.cs,535\" rel=\"noopener noreferrer nofollow\"><em><u>\u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442<\/u><\/em><\/a><em><u> \u0432 .NET Framework:<\/u><\/em><\/p>\n<ol>\n<li>\n<p><em><u>\u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 ExecutionContext.Capture() \u0434\u043b\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/u><\/em><\/p>\n<\/li>\n<li>\n<p><em><u>\u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 MoveNextRunner \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043a\u0430\u043a \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0442\u0430\u043a \u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u0443\u044e(boxed) \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b (\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443 \u043d\u0430\u0441 \u0435\u0449\u0435 \u043d\u0435\u0442, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c null \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f).<\/u><\/em> \u00ab\u0423\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0439(boxed)\u00bb \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0445\u0438\u043f\u0435, \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c<em><u>.<\/u><\/em><\/p>\n<\/li>\n<li>\n<p><em><u>\u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 Action \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 Run \u0432 \u044d\u0442\u043e\u043c MoveNextRunner; \u044d\u0442\u043e \u0442\u043e\u0442 \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c MoveNext \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e ExecutionContext.<\/u><\/em><\/p>\n<\/li>\n<li>\n<p><em><u>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0443 \u043d\u0430\u0441 \u0435\u0449\u0435 \u043d\u0435\u0442 boxed \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0435\u0435 \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u0445\u0438\u043f, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0443\u0436\u0435 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IAsyncStateMachine. \u0417\u0430\u0442\u0435\u043c \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 MoveNextRunner-\u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0436\u0435 \u0443\u0436\u0435 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d.<\/u><\/em><\/p>\n<\/li>\n<li>\n<p><em><u>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0448\u0435\u043b\u043e\u043c\u043b\u044f\u044e\u0449\u0438\u0439 \u0448\u0430\u0433. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 builder-\u043e\u0431\u044a\u0435\u043a\u0442: public AsyncTaskMethodBuilder &lt;>t__builder;, \u0438 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 builder-\u0430, \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 IAsyncStateMachine m_stateMachine;. \u041e\u0431\u044a\u0435\u043a\u0442\u0443-builder \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043d\u0430 \u0445\u0438\u043f\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f\u0445 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u043d \u043c\u043e\u0433 \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0443\u0436\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u0445\u0438\u043f, \u0438 \u0435\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043d\u043e\u0432\u0430. \u041d\u043e \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u0445\u0438\u043f, \u0438 \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u0435 builder \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 m_state Machine, \u0440\u0430\u0432\u043d\u043e\u0435 null. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0438\u0434\u043e\u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c m_stateMachine-\u043f\u043e\u043b\u0435 builder-\u0430 \u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e \u044d\u0442\u043e\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0445\u0438\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u0440\u0430\u043f\u0435\u0440-\u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u0430\u043a \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b). \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u0443\u044e, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IAsyncStateMachine, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \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 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 void SetStateMachine(IAsyncStateMachine StateMachine);, \u0438 \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/u><\/em><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cs\">private void SetStateMachine(IAsyncStateMachine stateMachine) =>     &lt;>t__builder.SetStateMachine(stateMachine);<\/code><\/pre>\n<p><em><u>\u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e: builder \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443 \u043d\u0430 \u0445\u0438\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u044d\u0442\u0443 \u0441\u0441\u044b\u043b\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 SetStateMachine, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 SetStateMachine builder, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043d\u0430 \u0445\u0438\u043f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. \u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0442, \u0431\u043b\u0438\u043d, \u043f\u0438\u0434\u0435\u0440\u0441\u0438\u044f.<\/u><\/em><\/p>\n<p>\u0422\u0443\u0442 \u043d\u0430\u0434\u043e \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u0430, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043b\u0435\u0433\u043a\u043e \u0438 \u043d\u0435\u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0435\u043d\u043d\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043b\u044e\u0431\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435 \u044d\u0442\u0430 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e 2 (\u0434\u0432\u0435!) \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435!<\/p>\n<ol start=\"6\">\n<li>\n<p><em><u>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434-Action, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u0438 \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0443 UnsafeOnCompleted awaiter-\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 TaskAwaiter \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u044d\u0442\u043e\u0442 Action \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u0430\u043a \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f, \u043e\u043d\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 Action, \u0447\u0435\u0440\u0435\u0437 MoveNextRunner.Run, \u0447\u0435\u0440\u0435\u0437 ExecutionContext.Run \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 MoveNext \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0432\u043e\u0439\u0442\u0438 \u0432 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0443 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u043e\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435.<\/u><\/em><\/p>\n<\/li>\n<\/ol>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044f\u043c\u0438<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0430\u0432\u0442\u043e\u0440 \u041f\u043e\u0441\u0442\u0430 \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442 \u043d\u0430\u0441 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0437\u044f\u0442\u043e\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430.<\/p>\n<pre><code class=\"cs\">using System.Threading; using System.Threading.Tasks;  class Program {     static async Task Main()     {         var al = new AsyncLocal&lt;int>() { Value = 42 };         for (int i = 0; i &lt; 1000; i++)         {             await SomeMethodAsync();         }     }      static async Task SomeMethodAsync()     {         for (int i = 0; i &lt; 1000; i++)         {             await Task.Yield();         }     } }<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u0438\/\u0438\u043b\u0438 \u043a\u043e\u0434 \u044f\u0434\u0440\u0430) \u0432 .NET Core \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 .NET Framework.<\/p>\n<p>\u0414\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u0434\u0430 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432 .NET Framework \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b(!) \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u043e\u0434\u0430, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 .NET Core \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435\u0433\u043e \u0442\u044b\u0441\u044f\u0447\u0443 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a ~145MB \u043f\u0440\u043e\u0442\u0438\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 109\u041a\u0411, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0442\u044b\u0441\u044f\u0447\u0443 \u0440\u0430\u0437.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0440\u0430\u0437\u0431\u043e\u0440 \u044d\u0442\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438 \u043f\u0440\u0438\u0447\u0438\u043d \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u043a \u0442\u0430\u043a\u043e\u0439 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u0442\u0430\u043a \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0430\u0447 (Tasks), \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u0434\u0430\u0447 (AsyncMethodBuilder), \u0430waiter-\u0430 (TaskAwaiter) \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e C# \u043a\u043e\u0434\u0430. \u042f \u0433\u0434\u0435-\u0442\u043e \u0447\u0438\u0442\u0430\u043b \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u044f\u0437\u044b\u043a\u0430 C# \u0441\u043b\u0430\u0432\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c, \u0438 \u0442\u0443\u0442 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u00a0\u0412\u044b\u0440\u0430\u0436\u0430\u044e \u0438\u0441\u043a\u0440\u0435\u043d\u043d\u0435\u0435 \u0432\u043e\u0441\u0445\u0438\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043c \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438 \u0441\u043c\u043e\u0433 \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u043e\u043b\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c:<\/p>\n<p>\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u0434\u0430\u0447-<em><u>builder-\u0430<\/u><\/em> (AsyncMethodBuilder);<\/p>\n<p>\u0430waiter-\u0430 (TaskAwaiter);<\/p>\n<p>\u0432\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0444\u043e\u0440\u043c\u0430\u043d\u0441\u0435.<\/p>\n<p>\u0421 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u043c\u0438 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f\u043c\u0438,<\/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\/792782\/\"> https:\/\/habr.com\/ru\/articles\/792782\/<\/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>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b Stephen Toub-\u0430: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/how-async-await-really-works\/\" rel=\"noopener noreferrer nofollow\">\u00abHow Async\/Await Really Works in C#\u00bb<\/a>. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437, \u0432 \u0441\u043b\u0435\u0434 \u0437\u0430 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 C# \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u044d\u0442\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439-\u043f\u043e\u043d\u044f\u0442\u0438\u0439-\u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a: \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0431\u043e\u043a\u0441\u0438\u043d\u0433, \u0441\u0442\u0435\u0439\u0442 \u043c\u0430\u0448\u0438\u043d\u0430, \u0441\u0442\u0435\u043a, \u043f\u043e\u0442\u043e\u043a\u0438, \u2026 \u042d\u0442\u0430 6-\u044f \u0447\u0430\u0441\u0442\u044c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u041a\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 Async\/Await \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 (\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f) \u0432 C#\u00bb<\/p>\n<p>\u0422\u0430\u043c, \u0433\u0434\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0446\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0434\u043e\u0441\u043b\u043e\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c), \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e <em><u>\u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044b\u043c \u043a\u0443\u0440\u0441\u0438\u0432\u043e\u043c<\/u><\/em>.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <a href=\"https:\/\/habr.com\/ru\/articles\/732738\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c<\/a>.<\/p>\n<hr\/>\n<p>\u0418\u0442\u0430\u043a, \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434:   <\/p>\n<pre><code class=\"cs\">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>\u041e\u043d \u043f\u043e\u044f\u0441\u043d\u044f\u0435\u0442 \u043d\u0430\u043c \u0447\u0442\u043e <em><u>\u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u043e\u043c, \u00ab\u0433\u043b\u043e\u0442\u043a\u043e\u043c \u0441\u0432\u0435\u0436\u0435\u0433\u043e \u0432\u043e\u0437\u0434\u0443\u0445\u0430\u00bb \u0432\u044b\u0440\u0430\u0436\u0430\u044f\u0441\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u043e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u043c\u0438 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/u><\/em><\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">public void CopyStreamToStream(Stream source, Stream destination) {     var buffer = new byte[0x1000];     int numRead;     while ((numRead = source.Read(buffer, 0, buffer.Length)) != 0)     {         destination.Write(buffer, 0, numRead);     } }<\/code><\/pre>\n<p><em><u>\u0412\u0441\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438(\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043b\u0438) \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c async \u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 void \u043d\u0430 Task, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439: ReadAsync, WriteAsync \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 Read, Write, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a \u044d\u0442\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u0430\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 await. \u0418 \u044d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u044f\u0434\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u044f \u0442\u043e, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043a\u043e\u0434. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c.<\/u><\/em><\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u0440\u043c\u0438\u043d <em><u>&#171;\u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430&#187;<\/u><\/em>. \u042d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0418\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 MoveNext() \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. \u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u0443\u0434\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u041f\u043e\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0442\u0435\u0440\u043c\u0438\u043d \u0432 \u0442\u043e\u0439 \u0436\u0435 \u043c\u0430\u043d\u0435\u0440\u0435.<\/p>\n<p><em><u>\u041c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u0447\u0442\u043e, \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0434\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0434 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0434\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (<\/u><\/em><code>public Task CopyStreamToStreamAsync(Stream source, Stream destination)<\/code><em><u>), \u043d\u043e \u0442\u0435\u043b\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0438\u043d\u044b\u043c:<\/u><\/em><\/p>\n<pre><code class=\"cs\">[AsyncStateMachine(typeof(&lt;CopyStreamToStreamAsync>d__0))] public Task CopyStreamToStreamAsync(Stream source, Stream destination) {     &lt;CopyStreamToStreamAsync>d__0 stateMachine = default;     stateMachine.&lt;>t__builder = AsyncTaskMethodBuilder.Create();     stateMachine.source = source;     stateMachine.destination = destination;     stateMachine.&lt;>1__state = -1;     stateMachine.&lt;>t__builder.Start(ref stateMachine);     return stateMachine.&lt;>t__builder.Task; }  private struct &lt;CopyStreamToStreamAsync>d__0 : IAsyncStateMachine {     public int &lt;>1__state;     public AsyncTaskMethodBuilder &lt;>t__builder;     public Stream source;     public Stream destination;     private byte[] &lt;buffer>5__2;     private TaskAwaiter &lt;>u__1;     private TaskAwaiter&lt;int> &lt;>u__2;      ... }<\/code><\/pre>\n<p><em><u>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, &#8212; \u044d\u0442\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 async. \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 async \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u0430; \u043a\u0430\u043a \u0438 unsafe. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u0430, \u0432\u044b \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430<\/u><\/em> (\u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438)<em><u>, \u0430 \u043d\u0435 \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 async\/await \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c.<\/u><\/em><\/p>\n<p><em><u>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &lt;CopyStreamToStreamAsync>d__0, \u0438 \u043e\u043d \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043d\u0443\u043b\u044f\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u0441\u0442\u0435\u043a\u0435. \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043a\u0438\u043d\u0435\u0442 \u0441\u0442\u0435\u043a. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u043e \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438), \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0430-\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0432\u0438\u0441\u043d\u0435\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 await, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0432\u0438\u0441\u043d\u0435\u0442 \u043d\u0430 \u0447\u0435\u043c-\u0442\u043e \u0447\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/u><\/em><\/p>\n<p><em><u>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u044e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0435 \u201c\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435\u201d \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0437\u0432\u043b\u0435\u043a \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 MoveNext. \u042d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 IEnumerable&lt;T>\/IEnumerator&lt;T>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 <\/u><\/em><a href=\"https:\/\/habr.com\/ru\/articles\/790944\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/em><\/a><em><u>. (\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u0432\u0437\u044f\u0442 \u0438\u0437 \u0441\u0431\u043e\u0440\u043a\u0438 release; \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u0441\u0431\u043e\u0440\u043a\u0430\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 C# \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u0442\u0438\u043f\u044b \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435).<\/u><\/em><\/p>\n<p><em><u>\u041f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432\u044b\u0437\u043e\u0432 AsyncTaskMethodBuilder.Create(). \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430\u0445-Tasks, \u044f\u0437\u044b\u043a C# \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 (\u0442\u0438\u043f\u043e\u0432 \u201c\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445-\u0437\u0430\u0434\u0430\u0447\u0435\u201d) \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434<\/u><\/em><\/p>\n<pre><code class=\"cs\">public async MyTask CopyStreamToStreamAsync<\/code><\/pre>\n<p><em><u>\u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c MyTask, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u201cbuilder\u201d \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0441 \u0442\u0438\u043f\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 AsyncMethodBuilder:<\/u><\/em><\/p>\n<pre><code class=\"cs\">[AsyncMethodBuilder(typeof(MyTaskMethodBuilder))] public class MyTask {     ... }  public struct MyTaskMethodBuilder {     public static MyTaskMethodBuilder Create() { ... }      public void Start&lt;TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { ... }     public void SetStateMachine(IAsyncStateMachine stateMachine) { ... }      public void SetResult() { ... }     public void SetException(Exception exception) { ... }      public void AwaitOnCompleted&lt;TAwaiter, TStateMachine>(         ref TAwaiter awaiter, ref TStateMachine stateMachine)         where TAwaiter : INotifyCompletion         where TStateMachine : IAsyncStateMachine { ... }     public void AwaitUnsafeOnCompleted&lt;TAwaiter, TStateMachine>(         ref TAwaiter awaiter, ref TStateMachine stateMachine)         where TAwaiter : ICriticalNotifyCompletion         where TStateMachine : IAsyncStateMachine { ... }      public MyTask Task { get { ... } } }<\/code><\/pre>\n<p><em><u>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0442\u0430\u043a\u043e\u0439 \u201cbuilder\u201d \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/u><\/em>(-\u0444\u0430\u0431\u0440\u0438\u043a\u0430, \u0441\u043c\u043e\u0442\u0440\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u00bb) <em><u>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 (\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Task), \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0435\u0433\u043e \u043b\u0438\u0431\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (SetResult), \u043b\u0438\u0431\u043e \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c (SetException), \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439<\/u><\/em> ( \u0441\u043c\u043e\u0442\u0440\u0438 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u00bb \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/790944\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a> \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043c\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u00abasync\/await \u0432 C#\u00bb \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0447\u0442\u043e \u201cbuilder\u201d \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0418 \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0430\u043b\u0435\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430  \u201cbuilder\u201d)<\/p>\n<p><em><u>\u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c \u0441 await, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b<\/u><\/em> <em><u>(AwaitOnCompleted\/AwaitUnsafeOnCompleted). \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 System.Threading.Tasks.Task &#8212; \u0442\u0438\u043f\u0430, \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0432\u044f\u0437\u0430\u043d \u0441 AsyncTaskMethodBuilder. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u0430 \u0441\u0432\u044f\u0437\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 [AsyncMethodBuilder(&#8230;)], \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u043a \u0442\u0438\u043f\u0443, \u043d\u043e Task \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0432 C# \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0430\u043a\u043e\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <\/u><\/em>(\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u0435\u043d \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Task, \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438)<em><u>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 Create, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b, AsyncTaskMethodBuilder \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0445\u0438\u043f\u0435 (\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438).<\/u><\/em><\/p>\n<p><em><u>\u0417\u0430\u0442\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 MoveNext, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. MoveNext \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0432\u0441\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 MoveNext, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u043c\u043e\u0433 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0438\u0445 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 MoveNext. \u0421\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c -1, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f MoveNext \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e -1, \u043c\u044b \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/u><\/em><\/p>\n<p><em><u>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u0430\u044f \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f, \u043d\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430: \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Start \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0442\u0438\u043f\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e* async \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e MoveNext \u043d\u0430 \u0441\u0442\u0435\u0439\u0442-\u043c\u0430\u0448\u0438\u043d\u0435. \u041c\u0435\u0442\u043e\u0434 Start \u201cbuilder\u201d-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e:<\/u><\/em><\/p>\n<pre><code class=\"cs\">public void Start&lt;TStateMachine>(ref<\/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-367853","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367853","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=367853"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367853\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}