我有简单的功能来写文件。
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();
}
如何将我的代码转换为StreamWriter.WriteAsync
与 try-catch 一起使用?