123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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();
- }
- }
- }
- }
|