【发布时间】:2013-09-22 19:29:31
【问题描述】:
我有简单的写文件功能。
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?
【问题讨论】:
标签: c# asynchronous try-catch .net-4.5 streamwriter