protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         SaveHeader();
         dset?.Dispose();
         var info = Hdf5.GroupInfo(_groupId);
         _groupId = Hdf5.CloseGroup(_groupId);
         fileId   = Hdf5.CloseFile(fileId);
     }
 }
 protected virtual void Dispose(bool disposing)
 {
     Trace.WriteLine($"saving file {Header.Patient.Name} samples: {_sampleCount}; fileId: {fileId}");
     Header.Recording.EndTime     = Header.Recording.StartTime + TimeSpan.FromSeconds(_sampleCount / Header.Recording.SampleRate);
     Header.Recording.NrOfSamples = _sampleCount;
     Header.EventListToEvents();
     for (int i = 0; i < Header.Channels.Count(); i++)
     {
         Header.Channels[i].NrOfSamples = _sampleCount;
     }
     Trace.WriteLine($"writing file {Header.Patient.Name} groupId: {_groupId}; fileId: {fileId}");
     Hdf5.WriteObject(_groupId, Header);
     if (disposing)
     {
         if (dset != null)
         {
             dset.Dispose();
         }
         var info = Hdf5.GroupInfo(_groupId);
         _groupId = Hdf5.CloseGroup(_groupId);
         fileId   = Hdf5.CloseFile(fileId);
     }
 }