I've been trying to make this work, but seems the program freeze. When i use .Result to return the binary data. I've not used Async before, sorry for my newbie code. It works perfect when i read the file as usual, but not async.
private static SaveData LoadFile()
{
string path = "/save.dat";
if (!File.Exists(path))
{
return null;
}
SaveData data = data = ZeroFormatterSerializer.Deserialize<SaveData>(ReadAllFileAsync(path).Result);
return data;
}
private static async Task<byte[]> ReadAllFileAsync(string path)
{
using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
{
byte[] result = new byte[file.Length];
await file.ReadAsync(result, 0, (int)file.Length);
return result;
}
}