Await in catch block

前端 未结 9 1500
醉梦人生
醉梦人生 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:40

    Give this a try:

             try
            {
                await AsyncFunction(...);
            }
    
            catch(Exception ex)
            { 
                Utilities.LogExceptionToFile(ex).Wait();
                //instead of "await Utilities.LogExceptionToFile(ex);"
            }
    

    (See the Wait() ending)

提交回复
热议问题