gpt4 book ai didi

c# - 如何检查字节数组中有多少位?

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:29 24 4
gpt4 key购买 nike

我正在创建一个下载速度测试,我将一个 800 兆位的文件下载到内存流中的一个 Byte[]

webClient.DownloadDataAsync(new Uri(link), memStreamArray); 

如何在下载时检查 memStreamArray 中有多少位?我需要这个,所以我可以计算大小/时间以获得实时速度。

我计划在 webClient.DownloadProgressChanged 事件中执行此计算。

最佳答案

为此,您需要一个 DownloadProgressChanged 事件处理程序。 DownloadDataAsync 方法中的第二个参数只是一个您可以在回调 UserState 变量中检索的对象,它只是传递 - 您可能在您的方案中没有用到它。

WebClient webClient = new WebClient();
webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine(e.BytesReceived);
};

webClient.DownloadDataAsync(new Uri(link));

关于c# - 如何检查字节数组中有多少位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com