Task.IsFaulted is not working in my .Net core application

后端 未结 1 1090
轮回少年
轮回少年 2021-01-28 02:46

Task.IsFaulted is not capturing exception. It seems that IsFault is not working. It is sending to else block even the condition is false. Can you plea

1条回答
  •  走了就别回头了
    2021-01-28 03:24

    Instead of using IsFaulted, just use try/catch:

    try
    {
      await _emailSender.SendEmailAsync(contentRootPath, email, subject, comment, userid, fullname);
      return @" 
                                        
                                        
                                        
                                            
                                            MCP Feedback Facility
                                        
                                        
                                            


    Feedback submitted successfully.

    "; } catch { return @" MCP Feedback Facility


    Sorry, your feedback submission was not completed successfully

    "; }

    Side note: return await Task.FromResult(responseString); is just a less efficient and less maintainable version of return responseString;

    0 讨论(0)
提交回复
热议问题