private void Reset() { if (!CanReset) { throw new InvalidOperationException("Event stream is not resetable (e.g. real time)."); } for (int i = 0; i < handles.Length; i++) { if (handles[i] != TraceEventNativeMethods.INVALID_HANDLE_VALUE) { TraceEventNativeMethods.CloseTrace(handles[i]); handles[i] = TraceEventNativeMethods.INVALID_HANDLE_VALUE; } // Annoying. The OS resets the LogFileMode field, so I have to set it up again. if (!useClassicETW) { logFiles[i].LogFileMode = TraceEventNativeMethods.PROCESS_TRACE_MODE_EVENT_RECORD; logFiles[i].LogFileMode |= TraceEventNativeMethods.PROCESS_TRACE_MODE_RAW_TIMESTAMP; } handles[i] = TraceEventNativeMethods.OpenTrace(ref logFiles[i]); if (handles[i] == TraceEventNativeMethods.INVALID_HANDLE_VALUE) { Marshal.ThrowExceptionForHR(TraceEventNativeMethods.GetHRForLastWin32Error()); } } }
protected override void Dispose(bool disposing) { if (handles != null) { foreach (ulong handle in handles) { if (handle != TraceEventNativeMethods.INVALID_HANDLE_VALUE) { TraceEventNativeMethods.CloseTrace(handle); } } handles = null; } base.Dispose(disposing); GC.SuppressFinalize(this); }
private void Reset() { if (!CanReset) { throw new InvalidOperationException("Event stream is not resetable (eg Real time)"); } // Annoying. The OS resets the LogFileMode field, so I have to set it up again. if (!useClassicETW) { primaryLogFile.LogFileMode = TraceEventNativeMethods.PROCESS_TRACE_MODE_EVENT_RECORD; } if (handles.Length > 1) { if (handles[1] != TraceEventNativeMethods.INVALID_HANDLE_VALUE) { TraceEventNativeMethods.CloseTrace(handles[1]); } kernelModeLogFile.LogFileMode = primaryLogFile.LogFileMode; handles[1] = TraceEventNativeMethods.OpenTrace(ref kernelModeLogFile); if (TraceEventNativeMethods.INVALID_HANDLE_VALUE == handles[1]) { Marshal.ThrowExceptionForHR(TraceEventNativeMethods.GetHRForLastWin32Error()); } } if (handles[0] != TraceEventNativeMethods.INVALID_HANDLE_VALUE) { TraceEventNativeMethods.CloseTrace(handles[0]); } handles[0] = TraceEventNativeMethods.OpenTrace(ref primaryLogFile); if (TraceEventNativeMethods.INVALID_HANDLE_VALUE == handles[0]) { Marshal.ThrowExceptionForHR(TraceEventNativeMethods.GetHRForLastWin32Error()); } }