public override void Dispose()
 {
     _isDisposing = true;
     lock (_disposeLock)
     {
         _spectra.Dispose();
         _scanIdList = null;
         if (_chromGroups != null)
         {
             _chromGroups.Dispose();
             _chromGroups = null;
         }
     }
     _collectors = null;
 }
        public override void SetRequestOrder(IList<IList<int>> chromatogramRequestOrder)
        {
            if (_isSrm)
                return;

            if (_chromGroups != null)
                _chromGroups.Dispose();

            _chromGroups = new ChromGroups(chromatogramRequestOrder, _collectors.ChromKeys, (float) (MaxRetentionTime ?? 30), _cachePath);
            _blockWriter = new BlockWriter(_chromGroups);

            if (!_collectors.IsRunningAsync)
                ExtractChromatograms();
            else
            {
                ActionUtil.RunAsync(() =>
                {
                    try
                    {
                        ExtractChromatograms();
                    }
                    catch (Exception ex)
                    {
                        if (_collectors == null)
                            throw;

                        _collectors.SetException(ex);
                    }
                }, "Chromatogram extractor"); // Not L10N
            }
        }
            /// <summary>
            /// Called from the reader thread to get a chromatogram. May have to wait until the chromatogram
            /// extraction thread has completed the requested chromatogram.
            /// </summary>
            public int ReleaseChromatogram(
                int chromatogramIndex,
                ChromGroups chromGroups,
                out float[] times,
                out float[] intensities,
                out float[] massErrors,
                out int[] scanIds)
            {
                lock (this)
                {
                    while (_exception == null)
                    {
                        // Copy chromatogram data to output arrays and release memory.
                        var collector = _collectors[chromatogramIndex];
                        int status;
                        if (chromGroups != null)
                        {
                            status = chromGroups.ReleaseChromatogram(chromatogramIndex, _retentionTime, collector,
                                out times, out intensities, out massErrors, out scanIds);
                        }
                        else
                        {
                            collector.ReleaseChromatogram(null, out times, out intensities, out massErrors, out scanIds);
                            status = collector.StatusId;
                        }
                        if (status >= 0)
                        {
                            _collectors[chromatogramIndex] = null;
                            return status;
                        }
                        Monitor.Wait(this);
                    }
                }

                // Propagate exception from provider thread.
                Helpers.WrapAndThrowException(_exception);
                throw _exception;   // Unreachable code, but keeps compiler happy
            }