提交 8619882a 编写于 作者: M mattwar

Change FileTextLoader to open FileStream for asynchronous IO. (changeset 1355769)

上级 9f9b359e
......@@ -296,6 +296,24 @@ internal static FileStream OpenRead(string fullPath)
}
}
internal static FileStream OpenAsyncRead(string fullPath)
{
Debug.Assert(PathUtilities.IsAbsolute(fullPath));
try
{
return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous);
}
catch (IOException)
{
throw;
}
catch (Exception e)
{
throw new IOException(e.Message, e);
}
}
/// <summary>
/// Used to create a file given a path specified by the user.
/// paramName - Provided by the Public surface APIs to have a clearer message. Internal API just rethrow the exception
......
......@@ -70,8 +70,9 @@ public override async Task<TextAndVersion> LoadTextAndVersionAsync(Workspace wor
// Allowing other theads/processes to write or delete the file is essential for scenarios such as
// Rename refactoring where File.Replace API is invoked for updating the modified file.
TextAndVersion textAndVersion;
using (var stream = FileUtilities.OpenRead(this.path))
using (var stream = FileUtilities.OpenAsyncRead(this.path))
{
System.Diagnostics.Debug.Assert(stream.IsAsync);
var version = VersionStamp.Create(prevLastWriteTime);
var memoryStream = await this.ReadStreamAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
......
......@@ -70,7 +70,7 @@ private static async Task<MemoryStream> ReadFileAsync(string path, CancellationT
{
MemoryStream memoryStream = new MemoryStream();
var buffer = new byte[1024];
using (var stream = FileUtilities.OpenRead(path))
using (var stream = FileUtilities.OpenAsyncRead(path))
{
int bytesRead = 0;
do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册