(C#)如何获取从另一个网络位置流式传输字节数组的进度? [英] (C#) How to obtain the progress of a byte array streaming from another network location?

查看:82
本文介绍了(C#)如何获取从另一个网络位置流式传输字节数组的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
有人可以指导我解决这个问题吗?

我有一个Web服务,它返回一个字节数组,如下所示:

Hi everyone!
Could someone please guide me in this problem?

I have a webservice that returns a byte array as follows:

byte[] BAReturn = myWebService.GetData();<br />



返回的数据约为100MB.
我应该做一个进度条,它跟踪字节数组流传输完成的百分比.所以我要做的是创建一个计时器并在计时器内部进行操作,代码是

myProgressBar.Percent = (BAReturn.Length / SizeOfData) * 100;

其中SizeOfData是要传输的字节数组数据的已知大小.

现在的问题是,无论数据多大,它总是立即变为100.只是突然改变到100之前有一个很长的停顿.这意味着我不能使用BAReturn.Length来跟踪转移.

如何跟踪转移进度?
感谢一百万!!!!



The returned data is about 100MB.
I''m supposed to do a progressbar that tracks the percentage of completion of the transfer of the byte array stream. So what I did was to create a timer and insider the timer, the code is

myProgressBar.Percent = (BAReturn.Length / SizeOfData) * 100;

where SizeOfData is the known size of the byte array data to be transfered.

Now the problem is that it always just goes to 100 immediately no matter how big the data is. Just that there is a long pause before the sudden change to 100. This means i can''t use BAReturn.Length to track the transfer.

How can i go about tracking the progress of transfer?
Thanks a million!!!!

推荐答案

我认为您的整数除法问题会导致四舍五入.

这样会更好:

I think your problem in integer division and thus rounding error.

This would do much better:

// myProgressBar.Percent ...
myProgressBar.Value = (100 * BAReturn.Length) /SizeOfData;



要完全确定,您甚至可以执行以下操作:



To be completely sure, you can even do this:

double percent = (100d * BAReturn.Length) /SizeOfData;
myProgressBar.Value = (int)System.Math.Round(percent);




—SA




—SA


这篇关于(C#)如何获取从另一个网络位置流式传输字节数组的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆