<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=406505&amp;view=findpost&amp;p=3630919</guid>
        <pubDate>Wed, 21 Oct 2015 18:45:23 +0000</pubDate>
        <title>Асинхронный метод не работает. Почему?</title>
        <link>https://forum.sources.ru/index.php?showtopic=406505&amp;view=findpost&amp;p=3630919</link>
        <description><![CDATA[SO: Допустим, есть у нас контроллер MyController. В контроллере есть асинхронный метод WaitLabel() и функция GetLabel():<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;public async Task&#60;ActionResult&#62; WaitLabel()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string label = await Task.Run(() =&#62; GetLabel());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return View(&quot;WaitLabel&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;private string GetLabel()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread.Sleep(10000);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return &quot;Готово&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
<br>
Также есть представление WaitLabel и все остальное прочее.<br>
<br>
Так вот, при открытии страницы http://.../MyController/WaitLabel строчка с await не выполняется асинхронно. Браузер страницу не отображает, поток приостанавливается на 10 секунд, после чего выполнение продолжается и на экране появляется страница. Я же ожидаю, что страница отобразится в браузере сразу.<br>
<br>
Что я делаю не так?]]></description>
        <author>SO</author>
        <category>.NET: Web приложения</category>
      </item>
	
      </channel>
      </rss>
	