我在需要將數據寫入JSON文件的IoT Core中編寫UWP應用程序。JSON.net異步寫入文件
string output = JsonConvert.SerializeObject(project, Formatting.Indented);
string filePath = @"path/to/file.json";
File.WriteAllText(filePath, output);
當試圖運行程序,我得到一個錯誤信息說:
同步操作不應該在UI線程上執行。 考慮將此方法包裝在Task.Run中。
我意識到,同步寫入文件是一個壞主意,但我不能爲我的生活弄清楚如何異步做到這一點。我將如何去保存我的JSON文件?