c# - True Parallel Downloads -



c# - True Parallel Downloads -

this method using concurrent downloads.

public void downloadconcurrent(action method) { action[] methodlist = new action[concurent_downloads]; (int = 0; < concurent_downloads; i++) { methodlist[i] = method; } parallel.invoke(methodlist); }

i trying download urls simultaneously, no. of active downloads one.

like downloads invoke, 1 url start downloading data, not start progressing downloads.

i want downloads work parallel same time, unable accomplish that.

update: methord using queue, downloading diffrent urls, form queue.

instance members of webclient not thread safe, ensure have separate instances in each action. in method have shown seem multiplicating same action delegate multiple times. not downloading different urls, downloading same url multiple times. , because webclient not thread safe might run problems.

here's illustration of parallel downloads of multiple urls using tpl:

using system; using system.linq; using system.net; using system.threading.tasks; class programme { static void main() { var urls = new[] { "http://google.com", "http://yahoo.com", "http://stackoverflow.com" }; var tasks = urls .select(url => task.factory.startnew( state => { using (var client = new webclient()) { var u = (string)state; console.writeline("starting download {0}", u); string result = client.downloadstring(u); console.writeline("finished downloading {0}", u); } }, url) ) .toarray(); task.waitall(tasks); } }

c# .net windows download webclient

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -