Winform应用程序随机退出

时间:2014-03-24 21:18:49

标签: c# .net winforms webclient html-agility-pack

我有一个随机崩溃的Winform应用程序。该应用程序使用HtmlAgility的WebClient来解析html页面并从Web服务器下载图像。我尝试使用Try-Catch,但应用程序没有提供其他异常,它可以告诉我导致崩溃的原因,除了" 500内部服务器错误"。这是一些信息。任何人都可以帮我找到问题吗?

谢谢,

    '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));
}

1 个答案:

答案 0 :(得分:2)

“500内部服务器错误”是服务器端错误。您的服务器上发生错误,并将结果500发送到您的客户端。这会在WinForms客户端中导致异常。您的WinForms客户端没有编码足够的异常处理。改进客户端上的异常处理以优雅地处理异常。查看您的服务器以确定500错误发生的原因。