public static void StreamReadAsync(
Stream stream,
byte[] buffer,
int offset,
int count,
SynchronizationContextWrapper syncContext,
Action<int, Exception> callback)
{
Exception error = null;
int length = 0;
try
{
stream.BeginRead(buffer, offset, count,
delegate(IAsyncResult ar)
{
try
{
length = stream.EndRead(ar);
}
catch (Exception e)
{
error = e;
}
callback(length, error);
},
null);
}
catch (Exception e)
{
error = e;
callback(length, error);
}
}