Wisnu
asked on
Stream.BeginRead and Stream.EndRead in .NET Core
ASKER
Hi Andy,
Thank for the answer. Indeed, they exist in .NET Framework, however when I port the code to .NET Core, the compile error occurs. Here is my code:
Thank for the answer. Indeed, they exist in .NET Framework, however when I port the code to .NET Core, the compile error occurs. Here is my code:
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
private static Task<int> ReadFileAsync(string filePath)
{
Stream fs = File.OpenRead(filePath);
byte[] readBuffer = new Byte[fs.Length];
Task<int> readTask =
Task.Factory.FromAsync(
(Func<byte[],
int,
int,
AsyncCallback,
object,
IAsyncResult>)
fs.BeginRead,
(Func<IAsyncResult, int>)
fs.EndRead,
readBuffer,
0,
(int)fs.Length,
null);
readTask.ContinueWith(task =>
{
if (task.Status == TaskStatus.RanToCompletion)
{
IsFinish = true;
Console.WriteLine(
"Read {0} bytes from file {1}",
task.Result,
filePath);
}
fs.Dispose();
});
return readTask;
}
Ahhh - now I understand what you meant. I don't know what (or even if it exists) you would need in that case.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Saige, this is what I am looking for.
https://msdn.microsoft.com/en-us/library/zxt5ahzw(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
https://msdn.microsoft.com/en-us/library/525xt96h(v=vs.110).aspx
You might need a
using System.IO;
in the file to make it compile