diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs index 80226acdbcecd2..0665ac8f0b97d8 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -12,10 +12,11 @@ ** =============================================================================*/ -using System.Runtime.CompilerServices; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -170,6 +171,7 @@ public static bool IsEntered(object obj) [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool ObjWait(bool exitContext, int millisecondsTimeout, object obj); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { if (obj == null) @@ -177,21 +179,25 @@ public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) return ObjWait(exitContext, millisecondsTimeout, obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout) { return Wait(obj, millisecondsTimeout, false); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout) { return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj) { return Wait(obj, Timeout.Infinite, false); diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs index 9edaf81e8a878e..882ce2144892f7 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System.Threading { @@ -182,6 +183,7 @@ internal ThreadHandle GetNativeHandle() /// method on the IThreadable interface passed in the constructor. Once the /// thread is dead, it cannot be restarted with another call to Start. /// + [UnsupportedOSPlatform("browser")] public void Start(object? parameter) { // In the case of a null delegate (second call to start on same thread) @@ -196,6 +198,7 @@ public void Start(object? parameter) Start(); } + [UnsupportedOSPlatform("browser")] public void Start() { #if FEATURE_COMINTEROP_APARTMENT_SUPPORT diff --git a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs index bd511d1705471b..479f7f53944355 100644 --- a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs +++ b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs @@ -89,7 +89,9 @@ public static void SetData(System.LocalDataStoreSlot slot, object? data) { } public static void Sleep(int millisecondsTimeout) { } public static void Sleep(System.TimeSpan timeout) { } public static void SpinWait(int iterations) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Start() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Start(object? parameter) { } [System.ObsoleteAttribute("Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)] public void Suspend() { } diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index d2f60ac8cf5bd8..db8ef2cc2eda60 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -280,10 +280,15 @@ public static void TryEnter(object obj, ref bool lockTaken) { } public static void TryEnter(object obj, int millisecondsTimeout, ref bool lockTaken) { } public static bool TryEnter(object obj, System.TimeSpan timeout) { throw null; } public static void TryEnter(object obj, System.TimeSpan timeout, ref bool lockTaken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, System.TimeSpan timeout, bool exitContext) { throw null; } } public sealed partial class Mutex : System.Threading.WaitHandle diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs index 6f6003d5b5ff1a..62fa739b59ac98 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -80,6 +81,7 @@ public static bool IsEntered(object obj) return IsEnteredNative(obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { if (obj == null) @@ -87,12 +89,16 @@ public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) return ObjWait(exitContext, millisecondsTimeout, obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout, bool exitContext) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout) => Wait(obj, millisecondsTimeout, false); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj) => Wait(obj, Timeout.Infinite, false); public static void Pulse(object obj) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs index bf6f7a3430eea6..47b26c9dfb9f78 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -251,11 +252,13 @@ public static void Sleep(int millisecondsTimeout) internal static void UninterruptibleSleep0() => SleepInternal(0, false); + [UnsupportedOSPlatform("browser")] public void Start() { StartInternal(this); } + [UnsupportedOSPlatform("browser")] public void Start(object parameter) { if (m_start is ThreadStart)