Saturday 15 January 2011

c# - WebClient DownloadDataAsync blocking -



c# - WebClient DownloadDataAsync blocking -

i need async binary download , used webclient class. download async, exceptions. dns resolve seem work synchronously. if remote server not responding, app blocking "...cannot resolve" timeout. there way create asynchronous property or have utilize backgroundworker , reorganize download.

see system.net.dns dns resolution services can executed asynchronously.

you can utilize dns.gethostaddressesasync() or dns.gethostentryasync() method asynchronously given host name ip addresses or host entry information, respectively. can utilize resulting ip address info straight specify remote host webclient operations, bypassing dns resolution delay.

you state in comment doing following:

webclient wc = new webclient(); wc.proxy = null; wc.downloaddatacompleted += new downloaddatacompletedeventhandler(wc_downloaddatacompleted); wc.downloaddataasync(new uri("http://www.undefined-domain.com"));

i recommend along using await dns lookup, utilize download:

webclient wc = new webclient(); byte[] result = await wc.downloaddatataskasync("http://" + ipaddress.tostring());

(you may have fiddle getting ip address formatted dns result appropriate webclient)

if need more specific advice that, recommend prepare question it's clearer , (very important) includes code illustration showing you're doing , explaining how want different.

c# asynchronous dns

No comments:

Post a Comment