diff --git a/dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs b/dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs index b3957cd6c3a6..52c9966e99e7 100644 --- a/dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs +++ b/dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs @@ -1,5 +1,12 @@ using iOSApp1; +#if DEBUG +// Enable runtime checks to ensure some types are only used from the main (UI) thread +UIApplication.CheckForIllegalCrossThreadCalls = true; +// Enable runtime checks to ensure ObjC delegates and events (using their own delegates) are not mixed +UIApplication.CheckForEventAndDelegateMismatches = true; +#endif + // This is the main entry point of the application. // If you want to use a different Application Delegate class from "AppDelegate" // you can specify it here. diff --git a/src/AppKit/NSApplication.cs b/src/AppKit/NSApplication.cs index f21eb5b06917..cd0176803db6 100644 --- a/src/AppKit/NSApplication.cs +++ b/src/AppKit/NSApplication.cs @@ -35,8 +35,14 @@ namespace AppKit { public partial class NSApplication : NSResponder { + +#if NET + public static bool CheckForIllegalCrossThreadCalls { get; set; } + public static bool CheckForEventAndDelegateMismatches { get; set; } +#else public static bool CheckForIllegalCrossThreadCalls = true; public static bool CheckForEventAndDelegateMismatches = true; +#endif #if !(XAMCORE_4_0 && NET) #if NET diff --git a/src/UIKit/UIApplication.cs b/src/UIKit/UIApplication.cs index 5f018c589ac3..e5383ad899d6 100644 --- a/src/UIKit/UIApplication.cs +++ b/src/UIKit/UIApplication.cs @@ -42,8 +42,13 @@ partial class UIApplication #endif { static Thread? mainThread; +#if NET + public static bool CheckForIllegalCrossThreadCalls { get; set; } + public static bool CheckForEventAndDelegateMismatches { get; set; } +#else public static bool CheckForIllegalCrossThreadCalls = true; public static bool CheckForEventAndDelegateMismatches = true; +#endif #if !WATCH // We link with __Internal here so that this function is interposable from third-party native libraries.