开发者

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 CancelAsyncmethod to kill any outstanding operation that you no longer need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜