Merge pull request #4386 from Sergio0694/feature/nct-712-changes

Fix app domain unloading issue on .NET Framework
This commit is contained in:
Sergio Pedri 2021-11-18 19:22:45 +01:00 коммит произвёл GitHub
Родитель b20c6ce166 22ca6daafb
Коммит 4a09bf0453
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -41,6 +41,16 @@ namespace System
/// <param name="target">The target object to pass as argument to <paramref name="callback"/>.</param>
public static void Register(Action<object> callback, object target)
{
#if NETSTANDARD2_0
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
{
// On .NET Framework using a GC callback causes issues with app domain unloading,
// so the callback is not registered if that runtime is detected and just ignored.
// Users on .NET Framework will have to manually trim the messenger, if they'd like.
return;
}
#endif
_ = new Gen2GcCallback(callback, target);
}

Просмотреть файл

@ -30,6 +30,7 @@ namespace Microsoft.Toolkit.Mvvm.Messaging
/// The <see cref="WeakReferenceMessenger"/> type will automatically perform internal trimming when
/// full GC collections are invoked, so calling <see cref="Cleanup"/> manually is not necessary to
/// ensure that on average the internal data structures are as trimmed and compact as possible.
/// Note: this is not supported when running on .NET Framework, due to app domain unloading issues.
/// </para>
/// </remarks>
public sealed class WeakReferenceMessenger : IMessenger