Silverlight 4 - using 语句中的 WebClient
当从常规桌面应用程序使用 WebClient 类时,我可以使用 using 语句来确保清理网络资源:
using(Webclient wb = new WebClient())
{
}
但是在 Silverlight 中,我不能这样做,因为 WebClient 不是 IDisposable。
1) 为什么WebClient在silverlight中不是IDisposable?
2)还有其他方法可以确保网络资源被清理吗?
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 IDisposable in silverlight ?
2) Is there another way I can ensure that the network resources are cleaned up ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
silverlight WebClient没有实现IDisposable的原因是它只支持异步操作。由于您无法在 using 语句中正确包含异步操作,因此支持 using 将毫无意义。
您可以使用
CancelAsync
方法终止任何不再需要的未完成操作。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.