2014-03-24 57 views
0

我有一個隨機崩潰的Winform應用程序。該應用程序使用HtmlAgility的WebClient來解析html頁面並從Web服務器下載圖像。我嘗試使用Try-Catch,但是除了「500內部服務器錯誤」之外,應用程序並未向我提供其他例外情況,這些例外情況可以告訴我導致崩潰的原因。這裏有一些信息。任何人都可以幫我找到問題嗎?Winform應用程序隨機退出

感謝,

'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\ReImageProcess\bin\Debug\ReImageApp.exe', Symbols loaded. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
The thread '<No Name>' (0x27d0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2148) has exited with code 0 (0x0). 
The thread '<No Name>' (0x26e4) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2998) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1484) has exited with code 0 (0x0). 
The thread '<No Name>' (0x239c) has exited with code 0 (0x0). 
'ReImageApp.exe' (Managed (v4.0.30319)): Loaded 'C:\ReImageProcess\bin\Debug\HtmlAgilityPack.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x10e0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2acc) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2904) has exited with code 0 (0x0). 
The thread '<No Name>' (0x230c) has exited with code 0 (0x0). 
The thread '<No Name>' (0xecc) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2adc) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1f18) has exited with code 0 (0x0). 
The thread '<No Name>' (0x24e4) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x205c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x26c0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2700) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1fc0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2534) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2168) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2bd0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2754) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x22e0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2a50) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2bdc) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1c14) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x23d0) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1174) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x11f4) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1ab8) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2a38) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2674) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x16e8) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2710) has exited with code 0 (0x0). 
The thread '<No Name>' (0x22f0) has exited with code 0 (0x0). 
The thread '<No Name>' (0xd58) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0xf34) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1e80) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2be4) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1178) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1724) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2370) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2b90) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2434) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2b4c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x26d8) has exited with code 0 (0x0). 
The thread '<No Name>' (0xb2c) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1428) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1138) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1b0) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2228) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x22c4) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1670) has exited with code 0 (0x0). 
The thread '<No Name>' (0x166c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2828) has exited with code 0 (0x0). 
The thread '<No Name>' (0x28c0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1160) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1d14) has exited with code 0 (0x0). 
The thread '<No Name>' (0x12b8) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1b48) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2274) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1ca0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x904) has exited with code 0 (0x0). 
The thread '<No Name>' (0x16f0) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2928) has exited with code 0 (0x0). 
The thread '<No Name>' (0x4b8) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x261c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x1f20) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2a14) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1ecc) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2814) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x27a0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x181c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2a30) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2a18) has exited with code 0 (0x0). 
The thread '<No Name>' (0x26c4) has exited with code 0 (0x0). 
The thread '<No Name>' (0x11e0) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x247c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2960) has exited with code 0 (0x0). 
The thread '<No Name>' (0x262c) has exited with code 0 (0x0). 
The thread '<No Name>' (0x114c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2a80) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x254c) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1898) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
The thread '<No Name>' (0x2a54) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2a78) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2bc0) has exited with code 0 (0x0). 
The thread '<No Name>' (0x2690) has exited with code 0 (0x0). 
The thread '<No Name>' (0x201c) has exited with code 0 (0x0). 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll 
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll 
The program '[10296] ReImageApp.exe: Managed (v4.0.30319)' has exited with code 0 (0x0). 

更新:

這裏是主要的LIB -

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Net; 
using System.IO; 
using System.Threading; 
using System.Configuration; 
using System.ComponentModel; 
using System.Text.RegularExpressions; 
using HtmlAgilityPack; 
using System.Drawing; 
using ImageManipulation; 
using System.Drawing.Imaging; 

namespace ReImageApp 
{ 
    class DownLoadImages 
    { 
     TextWriter tw2; 
     object objLocker = new object(); 
     Dictionary<string, string> dc = new Dictionary<string, string>(); 
     private Queue<string> _downloadImageUrls = new Queue<string>(); 
     private Queue<string> _loggerQueue = new Queue<string>(); 

     public DownLoadImages() 
     { 

     } 

     public DownLoadImages(TextWriter tw) 
     { 
      tw2 = tw; 
     } 

     public void AddImage2Queue(string url, string path) 
     { 
      _downloadImageUrls.Enqueue(url); 
      dc.Add(url, path); 
     } 


     public void RunHtmlAgilityPackThread(string url) 
     { 
      try 
      { 
       Thread.Sleep(Convert.ToInt16(ConfigurationManager.GetAppSetting("PauseTime")) * 1000); 
       WebClient linkclient = new WebClient(); 
       linkclient.DownloadDataCompleted += DownloadDataCompleted; 
       linkclient.DownloadDataAsync(new Uri(url), url); 
      } 
      catch (Exception ex) 
      { 
        _loggerQueue.Enqueue("Error in RunHtmlAgilityPackThread for url -- " + url + " " + (ex.InnerException == null? "" : ex.InnerException.Message)); 
      } 
     } 

     private void DownloadDataCompleted(object sender, 
      DownloadDataCompletedEventArgs e) 
     { 
      var url = (string)e.UserState; 

      try 
      { 
       byte[] dbytes = e.Result; 

       string responseStr = System.Text.Encoding.ASCII.GetString(dbytes); 
       HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); 
       document.LoadHtml(responseStr); 

       if (document.DocumentNode != null) 
       { 
        IList<string> ilImages = (document.DocumentNode.Descendants("img").Select(x => x.Attributes["src"].Value).Distinct().ToList()); 

        if (ilImages.Count == 0) 
        { 
          _loggerQueue.Enqueue("Warning (contains not image) in RunHtmlAgilityPackThread-- " + url); 

         return; 
        } 

        GetImageUrls(ilImages, url); 
       } 
       else 
       { 
         _loggerQueue.Enqueue("Warning (No Html doc node) in RunHtmlAgilityPackThread -- " + url); 
         return; 
       } 
      } 
      catch (WebException wx) 
      { 
        _loggerQueue.Enqueue("Error in RunHtmlAgilityPackThread -- " + (wx.InnerException == null ? "" : wx.InnerException.Message) + " url --" + url); 
      } 
      catch (Exception ex) 
      { 
        _loggerQueue.Enqueue("Error in RunHtmlAgilityPackThread -- " + (ex.InnerException == null ? "" : ex.InnerException.Message) + " url --" + url); 
      } 
     } 


     private void GetImageUrls(IList<string> imgs, string url){ 
        string url1, path; 

        try 
        { 
         for (int i = 0; i < imgs.Count; i++) 
         { 
          url1 = imgs[i].Replace("&amp;", "&"); 

          if (url1.ToLower().Contains("image1") || url1.ToLower().Contains("image2")) 
          { 
           lock (objLocker) 
           { 
            path = GetPath(url1, url); 
            if (url1 != null) 
            { 
             _downloadImageUrls.Enqueue(url1); 
             if (path != null) 
              dc.Add(url1, path); 
            } 
           } 
           DownloadFile(); 

          } 
         } 
        } 
        catch (Exception ex) 
        { 
          _loggerQueue.Enqueue("Error in GetImageUrls -- " + (ex.InnerException == null ? "" : ex.InnerException.Message)); 
        } 
      } 

     public void DownloadFile() 
     { 
      if (_downloadImageUrls.Any()) 
      { 
       try 
       { 
          WebClient imageclient = new WebClient(); 
          imageclient.DownloadFileCompleted += client_DownloadFileCompleted; 

          var url = _downloadImageUrls.Dequeue(); 
          string FileName = dc[url]; 

          CreateDirectory(Path.GetDirectoryName(FileName)); 
          imageclient.DownloadFileAsync(new Uri(url), FileName, FileName + " " + url); 
       } 
       catch (Exception ex) 
       { 
         _loggerQueue.Enqueue("Error in DownloadFile -- " + (ex.InnerException == null ? "" : ex.InnerException.Message)); 
       } 
       return; 
      } 

      // End of the download 
      return; 
     } 

     private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) 
     { 
      string filenameurl = string.Empty; 

      try 
      { 
       filenameurl = (string)e.UserState; 

       _loggerQueue.Enqueue(filenameurl); 

       if (e.Error != null) 
       { 
        _loggerQueue.Enqueue("Error in client_DownloadFileCompleted -- " + (e.Error.InnerException == null ? "" : e.Error.InnerException.Message)); 
       } 
       if (e.Cancelled) 
       { 
        // handle cancelled scenario 
       } 
      } 
      catch (Exception ex) 
      { 
      } 

      try 
      { 
       while(_loggerQueue.Count>0) 
        tw2.WriteLine(_loggerQueue.Dequeue()); 

       DownloadFile(); 
      } 
      catch (Exception ex) 
      { 
       _loggerQueue.Enqueue("Error in tw2.WriteLine -- " + (ex.InnerException == null? "" : ex.InnerException.Message)); 
      } 
      //mre.Set(); 
     } 


     private string GetPath(string url, string origUrl) 
     { 
      string strDestRoot = (string)ConfigurationManager.GetAppSetting("DestRoot"); 
      StringBuilder sb = new StringBuilder(strDestRoot); 
      StringBuilder sbFile = new StringBuilder(); 
      string strTableOrChart; 
      string strConcept; 
      string strSTCode; 
      string strCYCode; 
      string strGridCount; 
      string strMSCode; 

      try 
      { 
       string[] strParam0 = origUrl.Replace("&amp;", "&").Replace("&quot;", "").Split(new string[] { "?", "_Type=", "&Parameter1=", "&Parameter2=", "&" }, StringSplitOptions.RemoveEmptyEntries); 

       string[] strParam = url.Replace("&amp;", "&").Replace("&quot;", "").Split(new string[] { "?", "_Type=", "&Parameter1=", "&Parameter2=", "&" }, StringSplitOptions.RemoveEmptyEntries); 

       strTableOrChart = strParam[1]; 
       sb.Append(@"\"); 
       sb.Append(strTableOrChart); 

       strConcept = strParam0[2]; 
       sb.Append(@"\"); 
       sb.Append(strConcept); 
       CreateDirectory(sb.ToString()); 
       sb.Append(@"\"); 
       sb.Append(strConcept); 
       strSTCode = strParam[4]; 


       if (url.Contains("ImageCYTables?Table_Type=") || url.Contains("CYImage?Chart_Type=")) 
       { 
        strCYCode = strParam[5].Replace("Selected_CYCde=", ""); 
        sb.Append(strCYCode); 
       } 
       else if (url.Contains("MSImage?Chart_Type=") || url.Contains("ImageMSTable?Table_Type=")) 
       { 
        strMSCode = strParam[5].Replace("Selected_MSCde=", ""); 
        sb.Append(strMSCode); 
       } 
       else if (url.Contains("ImageTableMGrids?Table_Type=")) 
       { 
        if (strParam.Length > 5) 
        { 
         strGridCount = strParam[5].Replace("Parameter3=", "_"); 
         sb.Append(strGridCount); 
        } 
        else 
         sb.Append(strSTCode); 
       } 
       else if (url.Contains("ImageCYTable_MGrids?Table_Type=")) 
       { 
        strCYCode = strParam[5].Replace("Selected_CYCde=", ""); 
        strGridCount = strParam[6].Replace("Parameter3=", "_"); 
        sb.Append(strCYCode); 
        sb.Append(strGridCount); 
       } 
       else 
        sb.Append(strSTCode); 

       sb.Append(".png"); 
       return sb.ToString().Replace("\"", ""); 
      } 
      catch (Exception ex) 
      { 
       //lock (tw2) 
       { 
        _loggerQueue.Enqueue("Error in getpath -- " + (ex.InnerException == null ? "" : ex.InnerException.Message)); 
       } 
       return null; 
      } 
     } 

     private bool CreateDirectory(string path) 
     { 
      lock (objLocker) 
      { 
       if (!Directory.Exists(path)) 
       { 
        // Try to create the directory. 
        DirectoryInfo di = Directory.CreateDirectory(path); 
        return false; 
       } 
       else 
        return true; 
      } 
     } 
    } 
} 

用lib的部分是 -

   var doImages = GetDownLoadImagesThread(); 

       foreach (var aURL in iAllUrls.Distinct()) 
       { 
        doImages.Value.RunHtmlAgilityPackThread(aURL.Replace("&amp;", "&").Replace("\"","")); 
       } 


private ThreadLocal<DownLoadImages> GetDownLoadImagesThread() 
{ 
    TextWriter tw2 = new StreamWriter(CreateURLFile(2)); 
    tw2 = TextWriter.Synchronized(tw2); 

    return new ThreadLocal<DownLoadImages>(() => new DownLoadImages(tw2)); 
} 
+2

您能告訴我們一些代碼嗎? –

+0

代碼補充,謝謝 – Don

回答

2

「500內部服務器錯誤「是服務器端e RROR。錯誤發生在您的服務器上,並將結果500發送給您的客戶端。這會導致WinForms客戶端出現異常。您的WinForms客戶端沒有進行足夠的異常處理。改進客戶端的異常處理以優雅地處理異常。查看您的服務器以確定發生500錯誤的原因。

+0

我已經更新了主要庫。 「catch(Exception ex)」不足以捕獲所有?謝謝 – Don

+0

'catch(Exception)'應該足夠了,但是如果不仔細閱讀你的代碼,我不能說你需要在正確的地方使用'try ... catch'。你有一個堆棧跟蹤,指出異常的來源?如果沒有,您可以通過處理'AppDomain.Current'的'UnhandledException'和/或'FirstChanceException'事件來獲得更多信息。 –

+0

很奇怪。當我添加UnhandledException時,我現在可以看到SecondChanceException。 – Don