Await in catch block

前端 未结 9 1476
醉梦人生
醉梦人生 2020-11-28 11:14

I have the following code:

WebClient wc = new WebClient();
string result;
try
{
  result = await wc.DownloadStringTaskAsync( new Uri( \"http://badurl\" ) );
         


        
9条回答
  •  执笔经年
    2020-11-28 11:37

    Awaiting in a catch block is now possible as of the End User Preview of Roslyn as shown here (Listed under Await in catch/finally) and will be included in C# 6.

    The example listed is

    try … catch { await … } finally { await … }
    

    Update: Added newer link, and that it will be in C# 6

提交回复
热议问题