Is there a .NET 4.5 equivalent: Storagefile.Openasync

I fall in love with async and wait, but I cannot figure out how to wait for a file to open without using Task.Run. There is an API in WRT . Where is the equivalent of .NET 4.5? I ask because if I access a UNC resource on a remote machine, it can block for a very long time if the machine for some reason does not respond or does not respond to network requests. It looks like such a big site.

using (FileStream stream = await Task.Run(() => new FileStream(@"c:\temp\text.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read, 4096, true)))
{
  byte[] bytesToRead = new byte[stream.Length];    
  await stream.ReadAsync(bytesToRead, 0, bytesToRead.Length).ConfigureAwait(false);
  return bytesToRead;
}
+4
source share
2 answers

, , , Win32 API. , .NET; , , WinRT API , .

, : Task.Run. FileStream Task.Run.

+7
0

All Articles