Skip to content

Commit

Permalink
Enforced async I/O when opening a SystemFile
Browse files Browse the repository at this point in the history
By default, the stream returned from `File.Open` does synchronous operations on the file. We can make the underlying operating system give us an asynchronous file stream to do true async reads/writes.
  • Loading branch information
itsWindows11 committed Jun 19, 2024
1 parent c0aa68c commit 17ca687
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/System/IO/SystemFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public SystemFile(FileInfo info)
/// <inheritdoc />
public Task<Stream> OpenStreamAsync(FileAccess accessMode = FileAccess.Read, CancellationToken cancellationToken = default)
{
var stream = File.Open(Path, FileMode.Open, accessMode);
var stream = new FileStream(Path, FileMode.Open, accessMode, FileShare.None, 4096, FileOptions.Asynchronous);
cancellationToken.ThrowIfCancellationRequested();

return Task.FromResult<Stream>(stream);
Expand Down

0 comments on commit 17ca687

Please sign in to comment.