A software father's (un)conditional love for his twin programs
I have a C# program that fails pretty consistently. That's ok, I've created the program, it is my child, and I love it anyway. As a sort of support, I've decided to write a AutoHotKey wrapper around it, that automatically restarts the program until it finishes without an error. Now, I hope this doesn't make me a terrible father, but there's one more wish I have for the C# program:
If only it could fail without running to Windows 7 for help. The problem is that it requires me to say "Yes close the program, don't debug it." after Windows thinks it can find a solution to the problem.
How can I make the program simply fail without complaint? It has about 5500 more PDFs to consider, and I'll be proud if the twin programs can just sort things out among themselves.
This seems to have been solved already, but:
SetErrorMode seems able to deactivate the Windows Error Reporting dialog box entirely for your current process. (Tested and works for my artificial access violation.)
[DllImport("kernel32.dll")] public static extern uint SetErrorMode(uint uMode); // from msdn page
Set uMode to SEM_NOGPFAULTERRORBOX, that is 0x0002.
(btw: Seems you have created a lemming program, so you're a lemming father.)
Alternatively, if there is a module that fails a lot anyway, you could:
- Use System.Diagnostics.Process to start it as a separate process.
- Use another AppDomain (which is in process). If you detect a failure, unload the process.
I would try to solve the problem instead of trying to fight the symptom.
Fixing your child would be preferred path to take but alternatively, you can use following registry keys to disable the prompt
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting] "ForceQueue"=dword:00000001 "DontShowUI"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\Consent] "DefaultConsent"=dword:00000002