- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试通过请求许多文件下载来测试另一个应用程序。
因此,我使用以下代码启动了 10 个 WebClient
实例,但似乎我只能同时运行 5 个实例。
class Program
{
public static object locker = new object();
public static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
start(i);
Console.ReadLine();
}
private static void start(object row)
{
DateTime start = DateTime.Now;
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.DownloadProgressChanged += (sender, e) => {
lock (locker){
double throughput = e.BytesReceived /
(DateTime.Now - start).TotalSeconds / 1024 / 1024;
double error = 1 - (1 / throughput);
Console.SetCursorPosition(0, (int)row);
Console.WriteLine(
@"({0}) {1:HH\:mm\:ss.ffff} - {2:0.00}Mb - " +
@"{3:##0}% - {4:0.00}Mb/s ({5:+0.00%;-0.00%;0.00%}){6}",
row, DateTime.Now, e.BytesReceived / 1024 / 1024,
e.ProgressPercentage, throughput, error, " ");
}
};
client.DownloadFileAsync(
new Uri("http://site/Download.ashx?Id=123"),
String.Format("c:\\foo_{0}.xxx", row));
}
}
我得到以下输出:
(0) 14:51:07.1830 - 39,00Mb - 5% - 0,94Mb/s (-6,45%)(1) 14:51:06.8610 - 39,00Mb - 5% - 1,00Mb/s (+0,24%)(2) 14:51:06.5650 - 39,00Mb - 5% - 0,99Mb/s (-1,34%)(3) 14:51:07.2810 - 38,00Mb - 5% - 0,95Mb/s (-5,12%)(4) 14:51:06.5740 - 37,00Mb - 5% - 0,95Mb/s (-5,19%)(5) 14:50:30.4640 - 0,00Mb - 100% - 0,01Mb/s (-12690,64%)(6) 14:50:30.5390 - 0,00Mb - 100% - 0,01Mb/s (-12845,38%)(7) 14:50:30.8380 - 0,00Mb - 100% - 0,01Mb/s (-13909,70%)(8) 14:50:30.6150 - 0,00Mb - 100% - 0,01Mb/s (-12988,80%)(9) 14:50:30.9210 - 0,00Mb - 100% - 0,01Mb/s (-14079,53%)
我可以更改该限制以模拟更多并发用户吗?
最佳答案
一个原因可能是,您的服务器(扩展名为 .ashx 的 ASP.NET)仅从进程 4 请求并行下载文件。
您可以在 web.config 文件中更改它。
关于c# - 为什么我运行的 WebClient.DownloadFileAsync 不能超过 5 个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1602189/
我正在编写一个类库来在我无法控制的站点上执行操作。该网站正在接受表单帖子作为输入。 谁能告诉我这两种方法除了上传数据的形式之外是否有区别? System.Net.WebClient.Uploa
用于工作的代码。 有问题的网址是 https://yobit.net/api/3/info 它适用于 IE。它曾经与 webclient 一起使用。它现在在 webclient 中不起作用。我想知道问
因此,我将我的 WebClient 包装在一个 using 语句中。但是我突然想知道,如果我的对象实现了 IDisposable 并且包装在 using 语句中,我是否需要取消订阅事件? 下面是我当前
我正在 VS15 测试版中工作并尝试使用 WebClient。虽然 System.Net 被引用,并且智能感知建议 WebClient 类可用,但在构建时我收到以下错误: The type or na
我想知道是否可以将 cookie 从一个 Web 客户端复制到另一个 Web 客户端。 原因 我正在使用并行 Web 请求,它会在每个新线程上创建 Web 客户端的新实例。 问题 信息敏感,需要使用p
我正在尝试使用 WebClient,但它给我错误,所以我检查了几个论坛(包括这个),他们告诉我把它放在哪里 在文件的顶部: using System.Net 在我想使用 WebClient 的地方之后
我正在尝试使用 WebClient 实现以下场景。使用 RestTemplate 很简单,但我不能再这样做了。 伪java代码中Spring Controller 的相关部分: Mono t1 = w
我正在使用 Spring WebClient 调用休息服务。如下所述的 post 调用代码。 Mono response = client.post()
正在尝试使用 WebClient在 Blazor 项目中。 得到以下错误: 在 blazor.webassembly.js:1 WASM: System.Net.WebException: An ex
我正在使用 ASP.NET Core 并尝试将文件下载到绝对路径。 但我遇到的问题是文件总是被下载到项目目录,文件名本身得到整个路径的名称。 我的代码: string path = @"C:\User
我需要自动化涉及使用登录表单的网站的流程。我需要在登录页面之后的页面中捕获一些数据。 我知道如何对普通页面进行屏幕抓取,但不知道如何抓取安全站点背后的页面。 这可以通过 .NET WebClient
我正在尝试逐步下载一系列序列化数据。目标是从服务器发送一个大块,并在下载时在客户端对其进行部分处理。 我正在使用 System.Net.WebClient 类并将其 AllowReadStreamBu
我在 Windows 桌面应用程序上使用此代码来获取组合框的值,之后我需要选择哪个组合框将使用 JavaScript 使用新信息更新页面 private WebBrowser withEventsFi
我正在尝试通过 C# 代码获取网站的 HTML 源代码。当我使用 Windows 身份验证访问站点时,以下代码有效: using (WebClient client = new WebClient()
我只是使用WebClient.DownloadString(),但速度慢得惊人。最大速度为 40kbs 我尝试将 WebClient.Proxy 设置为 null,但这不起作用,而且我还没有达到最大互
为了利用新的 WebClient API,我在我的 Intellij 项目中包含了 spring-webflux。 dependencies { implementation 'org.spr
我已经开始使用 WebClient,并使用过滤器方法添加请求/响应日志记录: WebClient.builder() .baseUrl(properties.getEndpoint())
我正在使用 WebClient.DownloadFile 将图像下载到本地存储库,如下所示: WebClient myWC = new WebClient();
我尝试使用网络客户端非阻塞方法验证验证码响应。所以它的工作,但我需要我的方法返回 boolean 值而不是异常。我如何从订阅返回值? webClient
这个问题已经有答案了: What does a "Cannot find symbol" or "Cannot resolve symbol" error mean? (18 个回答) 已关闭 3 年
我是一名优秀的程序员,十分优秀!