I implement asynchronous download to retrieve remote file and store it in IsolatedStorage in order to use it when out of the network.
Everything works great when network is up. However when out of network, I noticed that async donwload may take up to 2 minutes before to fire my MessageBox (which say that connection to server has failed).
Question:
Is there any way to define a timeout ? Let’s say that if my application does not receive any answer for X seconds then stop the Async Download and call a method.
Maybe a timeout is not the best pratices. In this case could you give me suggestion ?
I do not want my user wait for 15 seconds max.
PS: my application is suppose to run on wifi only, so I consider that ‘network speed’ is optimal.
Thx for your help
What I would recommend doing is check the network type first via NetworkInterface. If NetworkInterfaceType is
Wireless80211, you have a wireless connection (Wi-Fi). The returned connection can beNonein case there is no available way to connect – so you won’t even have to start the download if there is no accessible network.Answering your question, if you are using
WebClient, you can’t define a timeout. However, you can callinstance.CancelAsync(). For aHttpWebRequestyou can callinstance.Abort().