private void ProcessTracesInSequence()

in Source/Tx.Windows/EtwNative/EtwFileReader.cs [129:185]


        private void ProcessTracesInSequence()
        {
            int error = 0;
            _handles = new ulong[_logFiles.Length];
            IntPtr startTime = ConvertDateTime(_startTime);
            IntPtr endTime = ConvertDateTime(_endTime);

            try
            {
                for (int i = 0; i < _logFiles.Length; i++)
                {
                    _handles[i] = EtwNativeMethods.OpenTrace(ref _logFiles[i]);

                    if (_handles[i] == EtwNativeMethods.InvalidHandle)
                    {
                        error = Marshal.GetLastWin32Error();
                        if (error == EtwNativeMethods.ErrorNotFound)
                        {
                            _observer.OnError(new FileNotFoundException("Could not find file " + _logFiles[i].LogFileName));
                            return;
                        }

                        _observer.OnError(new Win32Exception(error));
                        return;
                    }

                    error = EtwNativeMethods.ProcessTrace(new ulong[] { _handles[i] }, (uint)1, startTime, endTime);
                }
            }
            catch (Exception ex)
            {
                _observer.OnError(ex);
                return;
            }
            finally
            {
                if (startTime != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(startTime);
                    startTime = IntPtr.Zero;
                }

                if (endTime != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(endTime);
                    endTime = IntPtr.Zero;
                }
            }

            if (error != 0)
            {
                _observer.OnError(new Win32Exception(error));
                return;
            }

            _observer.OnCompleted();
        }