[英]Passing FileStream in WCF
After I pass a reference of filestream from the client to the service, and the service start downloading the stream to him, how can I determine, from the client side, how much bytes were read until now (while Im using the filestream object)? 在我将文件流的引用从客户端传递给服务,并且服务开始将流下载到他之后,如何确定从客户端到现在为止已读取了多少字节(而Im使用filestream对象)?
My goal is to calculate client's upload speed only for this file and the only way I can think of is this. 我的目标是仅计算此文件的客户端上载速度 ,而我能想到的唯一方法就是这样做。
Extend FileStream or create a wrapper for it. 扩展FileStream或为其创建包装。 Override the read methods and have a counter count the bytes read.
覆盖读取方法,并使计数器计数读取的字节数。
extending (not properly implement, but should be more than enough to explain) 扩展(未正确实施,但应该足以解释)
public class CountingStream : System.IO.FileStream {
// provide appropriate constructors
// may want to override BeginRead too
// not thread safe
private long _Counter = 0;
public override int ReadByte() {
_Counter++;
return base.ReadByte();
}
public override int Read(byte[] array, int offset, int count) {
// check if not going over the end of the stream
_Counter += count;
return base.Read(array, offset, count);
}
public long BytesReadSoFar {
get {
return _Counter;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.