How to use StreamWriter.WriteAsync and catch exceptions?
问题 I have simple function to write files. public static void WriteFile(string filename, string text) { StreamWriter file = new StreamWriter(filename); try { file.Write(text); } catch (System.UnauthorizedAccessException) { MessageBox.Show("You have no write permission in that folder."); } catch (System.Exception e) { MessageBox.Show(e.Message); } file.Close(); } How can I convert my code to use StreamWriter.WriteAsync with try-catch? 回答1: async public static void WriteFile(string filename, string