예제 #1
0
파일: program.cs 프로젝트: zhimaqiao51/docs
 protected virtual void Dispose(bool disposing)
 {
     // Note there are three interesting states here:
     // 1) CreateFile failed, _handle contains an invalid handle
     // 2) We called Dispose already, _handle is closed.
     // 3) _handle is null, due to an async exception before
     //    calling CreateFile. Note that the finalizer runs
     //    if the constructor fails.
     if (_handle != null && !_handle.IsInvalid)
     {
         // Free the handle
         _handle.Dispose();
     }
     // SafeHandle records the fact that we've called Dispose.
 }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            //Note there are three interesting states here:
            //值得注意的是,这有三种状态
            //1).CreateFile failed,_handle contains an invalid handle.
            //1)CreateFile失败,_handle包含无效句柄
            //2).We called Dispose already, _handle is closed.
            //2)我们已经调用了Dispose,句柄已关闭
            //3)._handle is null,due to an async exception before calling CreateFile.
            //3)_handle为空,因为在调用CreateFile之前发生了异步异常
            //Note that the finalizer runs if the constructor fails.
            //注意,如果构造函数失败,则终结器将运行
            if (_handle != null && !_handle.IsInvalid)
            {
                //Free the handle
                //释放句柄
                _handle.Dispose();
            }

            //SafeHandle records the fact that we've called Dispose.
            //SafeHandle记录了我们调用Dispose的事实
        }