@@ -345,8 +345,10 @@ private void ProcessCss(HtmlDocument doc)
345345 {
346346 if ( url . StartsWith ( "http" ) )
347347 {
348- var http = new WebClient ( ) ;
349- cssText = http . DownloadString ( url ) ;
348+ using ( var http = new WebClient ( ) )
349+ {
350+ cssText = http . DownloadString ( url ) ;
351+ }
350352 }
351353 else if ( url . StartsWith ( "file:///" ) )
352354 {
@@ -359,8 +361,10 @@ private void ProcessCss(HtmlDocument doc)
359361 url = uri . AbsoluteUri ;
360362 if ( url . StartsWith ( "http" ) && url . Contains ( "://" ) )
361363 {
362- var http = new WebClient ( ) ;
363- cssText = http . DownloadString ( url ) ;
364+ using ( var http = new WebClient ( ) )
365+ {
366+ cssText = http . DownloadString ( url ) ;
367+ }
364368 }
365369 else
366370 cssText = File . ReadAllText ( uri . LocalPath ) ;
@@ -418,8 +422,10 @@ private void ProcessScripts(HtmlDocument doc)
418422 {
419423 if ( url . StartsWith ( "http" ) )
420424 {
421- var http = new WebClient ( ) ;
422- scriptData = http . DownloadData ( url ) ;
425+ using ( var http = new WebClient ( ) )
426+ {
427+ scriptData = http . DownloadData ( url ) ;
428+ }
423429 }
424430 else if ( url . StartsWith ( "file:///" ) )
425431 {
@@ -432,8 +438,10 @@ private void ProcessScripts(HtmlDocument doc)
432438 url = uri . AbsoluteUri ;
433439 if ( url . StartsWith ( "http" ) && url . Contains ( "://" ) )
434440 {
435- var http = new WebClient ( ) ;
436- scriptData = http . DownloadData ( url ) ;
441+ using ( var http = new WebClient ( ) )
442+ {
443+ scriptData = http . DownloadData ( url ) ;
444+ }
437445 }
438446 else
439447 scriptData = File . ReadAllBytes ( uri . LocalPath ) ;
@@ -483,9 +491,11 @@ private void ProcessImages(HtmlDocument doc)
483491 {
484492 if ( url . StartsWith ( "http" ) )
485493 {
486- var http = new WebClient ( ) ;
487- imageData = http . DownloadData ( url ) ;
488- contentType = http . ResponseHeaders [ System . Net . HttpResponseHeader . ContentType ] ;
494+ using ( var http = new WebClient ( ) )
495+ {
496+ imageData = http . DownloadData ( url ) ;
497+ contentType = http . ResponseHeaders [ System . Net . HttpResponseHeader . ContentType ] ;
498+ }
489499 }
490500 else if ( url . StartsWith ( "file:///" ) )
491501 {
@@ -499,8 +509,10 @@ private void ProcessImages(HtmlDocument doc)
499509
500510 if ( uri . Scheme . StartsWith ( "http" ) )
501511 {
502- var http = new WebClient ( ) ;
503- imageData = http . DownloadData ( uri . AbsoluteUri ) ;
512+ using ( var http = new WebClient ( ) )
513+ {
514+ imageData = http . DownloadData ( uri . AbsoluteUri ) ;
515+ }
504516 }
505517 else
506518 imageData = File . ReadAllBytes ( uri . LocalPath ) ;
@@ -581,9 +593,11 @@ private string ProcessUrls(string html, string baseUrl)
581593 {
582594 if ( url . StartsWith ( "http" ) )
583595 {
584- var http = new WebClient ( ) ;
585- linkData = http . DownloadData ( url ) ;
586- contentType = http . ResponseHeaders [ HttpResponseHeader . ContentType ] ;
596+ using ( var http = new WebClient ( ) )
597+ {
598+ linkData = http . DownloadData ( url ) ;
599+ contentType = http . ResponseHeaders [ HttpResponseHeader . ContentType ] ;
600+ }
587601 }
588602 else if ( url . StartsWith ( "file:///" ) )
589603 {
@@ -602,8 +616,10 @@ private string ProcessUrls(string html, string baseUrl)
602616 url = uri . AbsoluteUri ;
603617 if ( url . StartsWith ( "http" ) && url . Contains ( "://" ) )
604618 {
605- var http = new WebClient ( ) ;
606- linkData = http . DownloadData ( url ) ;
619+ using ( var http = new WebClient ( ) )
620+ {
621+ linkData = http . DownloadData ( url ) ;
622+ }
607623 }
608624 else
609625 linkData = File . ReadAllBytes ( uri . LocalPath ) ;
@@ -673,12 +689,14 @@ protected void SetError(Exception ex, bool checkInner = false)
673689 {
674690 if ( ex == null )
675691 this . ErrorMessage = string . Empty ;
692+ else
693+ {
694+ Exception e = ex ;
695+ if ( checkInner )
696+ e = e . GetBaseException ( ) ;
676697
677- Exception e = ex ;
678- if ( checkInner )
679- e = e . GetBaseException ( ) ;
680-
681- ErrorMessage = e . Message ;
698+ ErrorMessage = e . Message ;
699+ }
682700 }
683701 #endregion
684702 }
0 commit comments