c# - Application crashes with "... stopped working" when brought to foreground -


i got request fix bug in tool created co-worker has left company.

this tool winforms-application based on .net-framework 4. works fine in general following situation lead random crashes:

if program in background (doesn't have focus) , brought foreground (focused / activated) user after while, crashes message "toolname has stopped working".

toolname replaced "vshost.exe" if it's executed under debugger. there no additional error message displayed. don't know line of code causes error.

some additional information:

  • if try force error activating window, activate window (for example outlook), activate window of tool again, crash tool (there must other leverage).
  • the mainform has no assigned event-handlers except form_load , form_sizechanged
  • the application uses weifenluo-docking-library , zedgraph-library.
  • i have impression error appears if application runned while.
  • the crash appears @ least on 2 computers run windows 7 x64. (i haven't tried other far)
  • i can't attach debbuger crashing process (neither visual studio 2010 nor 2013 work!). message

"the current debugger configured debug code uses microsoft .net framework v 1.0, 1.1, or 2.0. unhandled exception being thrown .net framework v4.0 code."

i tried obtain more information crash adding global exception handlers should create messagebox stack-trace don't fire:

[stathread] static void main() {   appdomain currentdomain = default(appdomain);   currentdomain = appdomain.currentdomain;    currentdomain.unhandledexception += globalunhandledexceptionhandler;   system.windows.forms.application.threadexception += globalthreadexceptionhandler;    // ... }  private static void globalunhandledexceptionhandler(object sender, unhandledexceptioneventargs e) {   exception ex = default(exception);   ex = (exception)e.exceptionobject;    messagebox.show(ex.message + "\n" + ex.stacktrace); }  private static void globalthreadexceptionhandler(object sender, system.threading.threadexceptioneventargs e) {   exception ex = default(exception);   ex = e.exception;    messagebox.show(ex.message + "\n" + ex.stacktrace); } 

in desparation added try-catch-block around application.run won't fire well:

try {    application.run(new mainform()); } catch (exception e) {    messagebox.show(e.message); } 

when run issues this, start event viewer. windows log application crashes event viewer, if silent. sometimes, able spit out stack trace can make things easier. experience, application silently crashing because trying load dependency missing , getting typeinitializationexception.

it hard me tell root cause without known more information application. application loading 3rd party libraries? custom control drawing happening in application? believe .net lazy loads types. if type isn't needed until application tries draw itself, may not loaded until application first shown. @ point, if type missing application crash. app start minimized? crashes random or consistent? meaning, if show application on start up, work? or crash when first display app?

what version of visual studio using? project file set .net 4? can select code type attach when attach process. in attach process dialog, press "select" right of attach (default should automatic: native code). select desired code type. option in same place vs 2010 , 2013.


Comments