winapi - C# app getting Watson dialog when calling TerminateProcess -


i have wpf application written in c# i'm using terminateprocess() when events happen , app needs shutdown

i'm not sure why, i'm seeing occasional watson dialog box appear when called? it's not 100%

is excepted? passing non-0 result code?

why watson popping, think silent exit?

[dllimport("kernel32.dll", setlasterror = true)] [return: marshalas(unmanagedtype.bool)] private static extern bool terminateprocess(intptr hprocess, uint uexitcode);  [dllimport("kernel32.dll")] private static extern intptr getcurrentprocess();  terminateprocess(getcurrentprocess(), 2);   <-- whats triggering watson (sometimes) 

you know calling terminateprocess close application jerking power plug out of wall shut down computer, right? doesn't ask nicely, , doesn't right thing. forcibly rips process out of memory.

it therefore makes deal of sense dr. watson debugger going pop up—no correctly functioning application going request terminated in such unusual way. 1 of threads you're terminating busy , didn't expect have rug ripped out underneath it. is, of course, not notified when call terminateprocess. there all kinds of things can go wrong here. dr. watson concludes has symptom of bug or other problem, steps in capture crash dump.

the exit code pass irrelevant here. can inspect after process has exited, not evaluated windows.

my suggestion not try , figure out keeping dr. watson appearing sometimes, rather find better way close application. if had provided more details design , why think need close app in first place, have made better suggestions. right now, can suggest call application.current.shutdown(). ensures application shut down right way, keep debugger being invoked. is, however, still irreversible action, should still want.

in win32 terms, since perhaps that's native language, correct way shut down application cleanly shut down of worker threads associated process first, , call exitprocess function. notice significance of naming—exit normal action, terminate not.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -