由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - WebClient is not thread-safe!
相关主题
WebClient for multi-connections?C#版ruby太慢了
Is there WinThread in C#a question about C++.net class library
LinqPad is handyHow to check a linked table?
webclient从yahoo finance读取页面的问题[合集] 问一个Response.WriteFile的问题
你们最不喜欢.net的什么?C#的new在method declaration里有和没有有啥区别么
.Net Thread question包子题: Implement GetFullPathOfIsolatedFile
谈谈我的.NETWindows filesystem bug
c#, c++光是数值运算的话,速度有多大区别? (转载)How to use openFileDialog() to save a binary file in .net C++
相关话题的讨论汇总
话题: webclient话题: url话题: thread话题: download话题: wc
进入DotNet版参与讨论
1 (共1页)
c**t
发帖数: 2744
1
Easy to test:
var links = new ConcurrentQueue(); //and populate with links
Parallel.For(0, link.Count, delegate(int i){
string url;
if( links.TryDeQueue(out url) )
{ Download(url); }
});
...
private void Download(string url)
{
using(WebClient wc = new WebClient())
{
wc.DownloadFile(url, somefilename);
}
}
a9
发帖数: 21638
2
这叫异步执行吧?

【在 c**t 的大作中提到】
: Easy to test:
: var links = new ConcurrentQueue(); //and populate with links
: Parallel.For(0, link.Count, delegate(int i){
: string url;
: if( links.TryDeQueue(out url) )
: { Download(url); }
: });
: ...
: private void Download(string url)
: {

c**d
发帖数: 579
3
This is not thread safety. And what issue does WebClient have?
c**t
发帖数: 2744
4
Only two links were downloaded, app doesn't stop, doesn't download more
links either.

【在 c**d 的大作中提到】
: This is not thread safety. And what issue does WebClient have?
d****d
发帖数: 133
5
you create one instace of wc per task, wc doesn't need to be thread-safe.

【在 c**t 的大作中提到】
: Only two links were downloaded, app doesn't stop, doesn't download more
: links either.

c**t
发帖数: 2744
6
read my code, each task has its own wc (using)

【在 d****d 的大作中提到】
: you create one instace of wc per task, wc doesn't need to be thread-safe.
v******n
发帖数: 421
7
how many cpu's (cores) in your machine? It is possible that TPL only
schedules
two threads

【在 c**t 的大作中提到】
: Only two links were downloaded, app doesn't stop, doesn't download more
: links either.

d****d
发帖数: 133
8
that's what I meant. wc doesn't need to be thread-safe if you write code
like
this. If it doesn't work, it has nothing to do with wc's thread-safety.

【在 c**t 的大作中提到】
: read my code, each task has its own wc (using)
d****d
发帖数: 133
9
I just wrote a test app. I have no problem downloading multiple urls at all.
At peak I have 6 downloading simultaneously.
Something else is wrong in your project. But as I said, it shouldn't have
anything to do with wc's thread safety.

【在 d****d 的大作中提到】
: that's what I meant. wc doesn't need to be thread-safe if you write code
: like
: this. If it doesn't work, it has nothing to do with wc's thread-safety.

s*****w
发帖数: 215
10
I also tested the above code,
multiple files are downloaded,
wc.DownloadFile(url, filename); the second parameter is the filename you are
going to download to. For each thread, they should have their own file
names.

【在 c**t 的大作中提到】
: Only two links were downloaded, app doesn't stop, doesn't download more
: links either.

1 (共1页)
进入DotNet版参与讨论
相关主题
How to use openFileDialog() to save a binary file in .net C++你们最不喜欢.net的什么?
How not to read comment lines from a text file.Net Thread question
刚去java版转了一圈谈谈我的.NET
问个best practicec#, c++光是数值运算的话,速度有多大区别? (转载)
WebClient for multi-connections?C#版ruby太慢了
Is there WinThread in C#a question about C++.net class library
LinqPad is handyHow to check a linked table?
webclient从yahoo finance读取页面的问题[合集] 问一个Response.WriteFile的问题
相关话题的讨论汇总
话题: webclient话题: url话题: thread话题: download话题: wc