From 2a0b09f015a3a4a4aa48ff3cbee0569afe6d1f0e Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Sat, 24 Feb 2024 14:03:44 -0800 Subject: [PATCH] Suppress fault message box --- Meds.Watchdog/Entrypoint.cs | 9 ++++++++- Meds.Wrapper/Entrypoint.cs | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Meds.Watchdog/Entrypoint.cs b/Meds.Watchdog/Entrypoint.cs index 71bbefc..41c6479 100644 --- a/Meds.Watchdog/Entrypoint.cs +++ b/Meds.Watchdog/Entrypoint.cs @@ -1,6 +1,6 @@ using System; using System.Globalization; -using System.Threading; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Meds.Dist; using Meds.Shared; @@ -16,8 +16,14 @@ namespace Meds.Watchdog { public sealed class Entrypoint { + [DllImport("kernel32.dll")] + private static extern uint SetErrorMode(uint uMode); + public static async Task Main(string[] args) { + // fail critical errors & no fault error box + SetErrorMode(3); + var culture = CultureInfo.GetCultureInfo("en-US"); CultureInfo.CurrentUICulture = culture; CultureInfo.CurrentCulture = culture; @@ -71,6 +77,7 @@ await Console.Error.WriteLineAsync( { await host.RunAsync(); } + // Force exit in case a background thread is frozen. Environment.Exit(0); } diff --git a/Meds.Wrapper/Entrypoint.cs b/Meds.Wrapper/Entrypoint.cs index c086479..f1f20ad 100644 --- a/Meds.Wrapper/Entrypoint.cs +++ b/Meds.Wrapper/Entrypoint.cs @@ -1,5 +1,7 @@ using System; using System.Globalization; +using System.Runtime.InteropServices; +using System.Threading.Tasks; using Meds.Shared; using Meds.Wrapper.Shim; using Microsoft.Extensions.DependencyInjection; @@ -17,8 +19,14 @@ public static class Entrypoint public static ILogger LoggerFor(Type type) => Instance?.Services.GetRequiredService().CreateLogger(type); + [DllImport("kernel32.dll")] + private static extern uint SetErrorMode(uint uMode); + public static void Main(string[] args) { + // fail critical errors & no fault error box + SetErrorMode(3); + var culture = CultureInfo.GetCultureInfo("en-US"); CultureInfo.CurrentUICulture = culture; CultureInfo.CurrentCulture = culture;