using System; namespace AIDiagnosisDemo.GC { internal class GcAdapter : IGcAdapter { private static GcAdapter _instance; public bool IsManualGc { get; set; } public static GcAdapter Instance { get { if (_instance == null) { _instance = new GcAdapter(); } return _instance; } } private GcAdapter() { IsManualGc = true; } public void SuppressFinalize(object obj) { if (IsManualGc) { System.GC.SuppressFinalize(obj); } } public void RegisterForFullGCNotification(int maxGenerationThreshold, int largeObjectHeapThreshold) { if (IsManualGc) { try { System.GC.RegisterForFullGCNotification(maxGenerationThreshold, largeObjectHeapThreshold); } catch (Exception e) { // ignored } } } public GCNotificationStatus WaitForFullGCApproach() { if (IsManualGc) { return System.GC.WaitForFullGCApproach(); } return GCNotificationStatus.Canceled; } public GCNotificationStatus WaitForFullGCComplete() { if (IsManualGc) { return System.GC.WaitForFullGCComplete(); } return GCNotificationStatus.Canceled; } public void WaitForPendingFinalizers() { if (IsManualGc) { System.GC.WaitForPendingFinalizers(); } } public int CollectionCount(int generation) { if (IsManualGc) { return System.GC.CollectionCount(generation); } return 0; } public void Collect() { if (IsManualGc) { System.GC.Collect(); } } public void Collect(int generation) { if (IsManualGc) { System.GC.Collect(generation); } } public void CancelFullGCNotification() { if (IsManualGc) {// TODO for net standard,this method is not implemented !!!! try { System.GC.CancelFullGCNotification(); } catch (Exception e) { // ignored } } } public void EndNoGCRegion() { if (IsManualGc) { System.GC.EndNoGCRegion(); } } } }