c# - Winform Application Exits Randomly -
i have winform application crashes randomly. application uses htmlagility's webclient parse html page , download images web server. try use try-catch application not provide me other exceptions can tell me causes crash, except "500 internal server error". here information. can me find problem?
thanks,
'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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' 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 optimized , debugger option 'just code' enabled. thread '<no name>' (0x27d0) has exited code 0 (0x0). thread '<no name>' (0x2148) has exited code 0 (0x0). thread '<no name>' (0x26e4) has exited code 0 (0x0). thread '<no name>' (0x2998) has exited code 0 (0x0). thread '<no name>' (0x1484) has exited code 0 (0x0). thread '<no name>' (0x239c) has exited code 0 (0x0). 'reimageapp.exe' (managed (v4.0.30319)): loaded 'c:\reimageprocess\bin\debug\htmlagilitypack.dll', skipped loading symbols. module optimized , debugger option 'just code' enabled. first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x10e0) has exited code 0 (0x0). thread '<no name>' (0x2acc) has exited code 0 (0x0). thread '<no name>' (0x2904) has exited code 0 (0x0). thread '<no name>' (0x230c) has exited code 0 (0x0). thread '<no name>' (0xecc) has exited code 0 (0x0). thread '<no name>' (0x2adc) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1f18) has exited code 0 (0x0). thread '<no name>' (0x24e4) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x205c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x26c0) has exited code 0 (0x0). thread '<no name>' (0x2700) has exited code 0 (0x0). thread '<no name>' (0x1fc0) has exited code 0 (0x0). thread '<no name>' (0x2534) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2168) has exited code 0 (0x0). thread '<no name>' (0x2bd0) has exited code 0 (0x0). thread '<no name>' (0x2754) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x22e0) has exited code 0 (0x0). thread '<no name>' (0x2a50) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2bdc) has exited code 0 (0x0). thread '<no name>' (0x1c14) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x23d0) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1174) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x11f4) has exited code 0 (0x0). thread '<no name>' (0x1ab8) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2a38) has exited code 0 (0x0). thread '<no name>' (0x2674) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x16e8) has exited code 0 (0x0). thread '<no name>' (0x2710) has exited code 0 (0x0). thread '<no name>' (0x22f0) has exited code 0 (0x0). thread '<no name>' (0xd58) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0xf34) has exited code 0 (0x0). thread '<no name>' (0x1e80) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2be4) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1178) has exited code 0 (0x0). thread '<no name>' (0x1724) has exited code 0 (0x0). thread '<no name>' (0x2370) has exited code 0 (0x0). thread '<no name>' (0x2b90) has exited code 0 (0x0). thread '<no name>' (0x2434) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2b4c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x26d8) has exited code 0 (0x0). thread '<no name>' (0xb2c) has exited code 0 (0x0). thread '<no name>' (0x1428) has exited code 0 (0x0). thread '<no name>' (0x1138) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1b0) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2228) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x22c4) has exited code 0 (0x0). thread '<no name>' (0x1670) has exited code 0 (0x0). thread '<no name>' (0x166c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2828) has exited code 0 (0x0). thread '<no name>' (0x28c0) has exited code 0 (0x0). thread '<no name>' (0x1160) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1d14) has exited code 0 (0x0). thread '<no name>' (0x12b8) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1b48) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2274) has exited code 0 (0x0). thread '<no name>' (0x1ca0) has exited code 0 (0x0). thread '<no name>' (0x904) has exited code 0 (0x0). thread '<no name>' (0x16f0) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2928) has exited code 0 (0x0). thread '<no name>' (0x4b8) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x261c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x1f20) has exited code 0 (0x0). thread '<no name>' (0x2a14) has exited code 0 (0x0). thread '<no name>' (0x1ecc) has exited code 0 (0x0). thread '<no name>' (0x2814) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x27a0) has exited code 0 (0x0). thread '<no name>' (0x181c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2a30) has exited code 0 (0x0). thread '<no name>' (0x2a18) has exited code 0 (0x0). thread '<no name>' (0x26c4) has exited code 0 (0x0). thread '<no name>' (0x11e0) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x247c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2960) has exited code 0 (0x0). thread '<no name>' (0x262c) has exited code 0 (0x0). thread '<no name>' (0x114c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2a80) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x254c) has exited code 0 (0x0). thread '<no name>' (0x1898) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll thread '<no name>' (0x2a54) has exited code 0 (0x0). thread '<no name>' (0x2a78) has exited code 0 (0x0). thread '<no name>' (0x2bc0) has exited code 0 (0x0). thread '<no name>' (0x2690) has exited code 0 (0x0). thread '<no name>' (0x201c) has exited code 0 (0x0). first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.reflection.targetinvocationexception' occurred in system.dll first chance exception of type 'system.io.directorynotfoundexception' occurred in mscorlib.dll program '[10296] reimageapp.exe: managed (v4.0.30319)' has exited code 0 (0x0).
update:
here main 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 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 { (int = 0; < imgs.count; i++) { url1 = imgs[i].replace("&", "&"); 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 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("&", "&").replace(""", "").split(new string[] { "?", "_type=", "¶meter1=", "¶meter2=", "&" }, stringsplitoptions.removeemptyentries); string[] strparam = url.replace("&", "&").replace(""", "").split(new string[] { "?", "_type=", "¶meter1=", "¶meter2=", "&" }, 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 create directory. directoryinfo di = directory.createdirectory(path); return false; } else return true; } } } }
the part use lib -
var doimages = getdownloadimagesthread(); foreach (var aurl in iallurls.distinct()) { doimages.value.runhtmlagilitypackthread(aurl.replace("&", "&").replace("\"","")); } private threadlocal<downloadimages> getdownloadimagesthread() { textwriter tw2 = new streamwriter(createurlfile(2)); tw2 = textwriter.synchronized(tw2); return new threadlocal<downloadimages>(() => new downloadimages(tw2)); }
"500 internal server error" server-side error. error occurring on server, , it's sending result 500 client. causes exception in winforms client. winforms client not coded sufficient exception handling. improve exception handling on client gracefully handle exceptions. @ server determine why 500 error occurring.
Comments
Post a Comment