-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevented C# bots from popping up exception dialogs if they threw
unhandled exceptions.
- Loading branch information
Matt Van Der Westhuizen
committed
Jun 1, 2015
1 parent
fc03e1e
commit 4040177
Showing
3 changed files
with
75 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ChallengeHarness.Runners | ||
{ | ||
/// <summary> | ||
/// Set the window's error mode for this process. Be very careful with this --- this is a process wide | ||
/// setting, so in a multi-threaded situation it can do crazy things! | ||
/// Code pulled from: http://msdn.microsoft.com/en-us/magazine/cc163866.aspx | ||
/// </summary> | ||
public struct ChangeErrorMode : IDisposable | ||
{ | ||
/// <summary> | ||
/// Error modes that can be enabled or disabled. | ||
/// </summary> | ||
[Flags] | ||
public enum ErrorModes | ||
{ | ||
Default = 0x0, | ||
FailCriticalErrors = 0x1, | ||
NoGpFaultErrorBox = 0x2, | ||
NoAlignmentFaultExcept = 0x4, | ||
NoOpenFileErrorBox = 0x8000 | ||
} | ||
|
||
private int _oldMode; | ||
|
||
/// <summary> | ||
/// Set the new error mode. When Dispose is called it will reset | ||
/// to the original value (use the "using" statement). | ||
/// </summary> | ||
/// <param name="mode"></param> | ||
public ChangeErrorMode(ErrorModes mode) | ||
{ | ||
_oldMode = SetErrorMode((int)mode); | ||
} | ||
|
||
void IDisposable.Dispose() { SetErrorMode(_oldMode); } | ||
|
||
[DllImport("kernel32.dll")] | ||
private static extern int SetErrorMode(int newMode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters