private static void AddListenerComponent(EventLogInternal component, string compMachineName, string compLogName) { lock (InternalSyncObject) { Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::AddListenerComponent(" + compLogName + ")"); LogListeningInfo info = (LogListeningInfo) listenerInfos[compLogName]; if (info != null) { Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::AddListenerComponent: listener already active."); info.listeningComponents.Add(component); return; } info = new LogListeningInfo(); info.listeningComponents.Add(component); info.handleOwner = new EventLogInternal(compLogName, compMachineName); // tell the event log system about it info.waitHandle = new AutoResetEvent(false); bool success = UnsafeNativeMethods.NotifyChangeEventLog(info.handleOwner.ReadHandle, info.waitHandle.SafeWaitHandle); if (!success) throw new InvalidOperationException(SR.GetString(SR.CantMonitorEventLog), SharedUtils.CreateSafeWin32Exception()); info.registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(info.waitHandle, new WaitOrTimerCallback(StaticCompletionCallback), info, -1, false); listenerInfos[compLogName] = info; } }
private static void AddListenerComponent(EventLogInternal component, string compMachineName, string compLogName) { lock (InternalSyncObject) { LogListeningInfo state = (LogListeningInfo) listenerInfos[compLogName]; if (state != null) { state.listeningComponents.Add(component); } else { state = new LogListeningInfo(); state.listeningComponents.Add(component); state.handleOwner = new EventLogInternal(compLogName, compMachineName); state.waitHandle = new AutoResetEvent(false); if (!Microsoft.Win32.UnsafeNativeMethods.NotifyChangeEventLog(state.handleOwner.ReadHandle, state.waitHandle.SafeWaitHandle)) { throw new InvalidOperationException(SR.GetString("CantMonitorEventLog"), SharedUtils.CreateSafeWin32Exception()); } state.registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(state.waitHandle, new WaitOrTimerCallback(EventLogInternal.StaticCompletionCallback), state, -1, false); listenerInfos[compLogName] = state; } } }