IDisposable

自己备用

public static class PHDApi : IDisposable
    {
        private PHDAccess _phd = null;
        // Track whether Dispose has been called.
        private bool disposed = false; 
        ~PHDApi()
        {
            Dispose(false);
        }
        public PHDAccess phd
        {
            get
            {
                if (_phd == null)
                    _phd = new PHDAccess();
                return _phd;
            }
            set
            {
                _phd = value;
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing && _phd != null)
                {
                    _phd.Dispose();
                    _phd = null;
                }
                disposed = true;
            }
        }
    }

 

posted @ 2017-11-20 15:03  Jearay  阅读(212)  评论(0编辑  收藏  举报