WebClient не переопределяет Dispose
, которое он наследует от Component
.
Не должно быть необходимости вызывать Dispose, и я не получаю ошибку, о которой вы упоминали.Пожалуйста, упомяните другой пост stackoverflow.
На самом деле, WebClient не сохраняет состояния, которое потребовало бы dsiposing и довольно без состояния.Глядя на реализацию в Reflector, становится очевидным, что он ищет ресурсы здесь (метод DownloadDataInternal
вызывается из DownloadString
):
private byte[] DownloadDataInternal(Uri address, out WebRequest request)
{
byte[] buffer2;
if (Logging.On)
{
Logging.Enter(Logging.Web, this, "DownloadData", address);
}
request = null;
try
{
request = this.m_WebRequest = this.GetWebRequest(this.GetUri(address));
buffer2 = this.DownloadBits(request, null, null, null);
}
catch (Exception exception)
{
if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
{
throw;
}
if (!(exception is WebException) && !(exception is SecurityException))
{
exception = new WebException(SR.GetString("net_webclient"), exception);
}
AbortRequest(request);
throw exception;
}
catch
{
Exception exception2 = new WebException(SR.GetString("net_webclient"), new Exception(SR.GetString("net_nonClsCompliantException")));
AbortRequest(request);
throw exception2;
}
return buffer2;
}