Silverlight 4 - WebClient in a using statement
When using the WebClient class from a regular desktop app, I can use in using statement to ensure that the network resources are cleaned up :
using(Webclient wb = new WebClient())
{
}
In Silverlight however, I can't do that because WebClient is not IDisposable.
1) Why WebClient is not IDisposa开发者_如何学运维ble in silverlight ?
2) Is there another way I can ensure that the network resources are cleaned up ?The reason silverlight WebClient does not implement IDisposable is because it only supports asynchronous operations. Since you cannot properly enclose asynchronous operations within a using statement supporting using would be meaningless.
You can use the CancelAsync
method to kill any outstanding operation that you no longer need.
精彩评论