private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    DisposeTokenSource?.Cancel();
                    DisposeTokenSource?.Dispose();

                    ReadHandle?.Dispose();
                    WriteHandle?.Dispose();
                }

                disposedValue = true;
            }
        }
        public bool WriteOpen()
        {
            bool result = false;

            if (!IsWriteOpened)
            {
                try
                {
                    WriteHandle.Dispose();
                    WriteHandle = Helper.OpenDevice(DeviceInfo.DevicePath, DesiredAccesses.GenericWrite,
                                                    ShareModes.FileShareRead | ShareModes.FileShareWrite, FileFlags.FileFlagOverlapped);
                    result = IsWriteOpened;
                }
                catch (Exception e)
                {
                    throw new DeviceCouldNotOpenedException($"This device could not {nameof(WriteOpen)}. Please check inner exception ({e.GetType()})", e);
                }
            }

            return(result);
        }
 public void WriteClose()
 {
     WriteHandle?.Dispose();
 }