Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建C#WebClient类后如何关闭浏览器?_C#_Webclient - Fatal编程技术网

创建C#WebClient类后如何关闭浏览器?

创建C#WebClient类后如何关闭浏览器?,c#,webclient,C#,Webclient,我提供了一个HTTP web服务,我的一个用户正在Windows 2003计算机上使用C#WebClient类从我的网站检索数据。我的用户说WebClient正在创建许多浏览器实例,需要关闭。浏览器创建后,他如何关闭浏览器 他的代码: Byte[] requestedHTML; WebClient client = new WebClient(); requestedHTML = client.DownloadData("http://abcabc.com/abc"); UTF8Encoding

我提供了一个HTTP web服务,我的一个用户正在Windows 2003计算机上使用C#WebClient类从我的网站检索数据。我的用户说WebClient正在创建许多浏览器实例,需要关闭。浏览器创建后,他如何关闭浏览器

他的代码:

Byte[] requestedHTML;
WebClient client = new WebClient();
requestedHTML = client.DownloadData("http://abcabc.com/abc");
UTF8Encoding objUTF8 = new UTF8Encoding();
string returnMessage = objUTF8.GetString(requestedHTML);
p、 如果这听起来很业余,我对C#很陌生,请向美国道歉。

WebClient
不使用浏览器,它只是底层协议的包装器。您应该使用添加一个
,但这与“许多浏览器实例”无关:


.NET Framework中的WebClient类保留了在Microsoft Windows中访问网络堆栈所需的一些系统资源。CLR的行为将确保最终清理这些资源

但是,如果手动调用
Dispose
或使用
using语句
,则可以在更可预测的时间清理这些资源。这可以提高大型程序的性能

using(WebClient client = new WebClient())
{
    // Do your operations here...
}

你可以参考这本漂亮的教程:

请不要道歉。我们在这里都是为了学习。如果可以的话,我也会赞扬你,因为你几乎在Marc Gravell之后立即发布了相同的答案。:)
using(WebClient client = new WebClient())
{
    // Do your operations here...
}