webclient不支持并发I/o操作的解决办法

2次阅读
没有评论

C#程序开发中,使用WebClient实例出现不支持并发I/O操作的异常提示“WebClient does not support concurrent I/O operations ”,解决方法也很简单,使用几个WebClient实例,就new几个WebClient

Stream stream1 = client1.OpenRead(URLAddress);
Stream stream2 = client2.OpenRead(URLAddress2);

在上述代码段中出现了两个client实例,一个是client1,一个是client2,为保证两行代码都能正常运行,就需要在代码段前new两个webclient实例

private WebClient client1 = new WebClient();
private WebClient client2 = new WebClient();//创建第二个WebClient实例,解决WebClient不能并发I/O操作问题