private void PollForTracingCommand(object state)
        {
            // Make sure that any transient errors don't cause the listener thread to exit.
            try
            {
                // Perform initialization when the timer fires for the first time.
                if (m_traceFilePath == null)
                {
                    // Set file paths.
                    m_traceFilePath  = GetDisambiguatedTraceFilePath(Config_EventPipeOutputFile);
                    m_markerFilePath = MarkerFilePath;

                    // Marker file is assumed to not exist.
                    // This will be updated when the monitoring thread starts.
                    m_markerFileExists = false;
                }

                // Check for existence of the file.
                // If the existence of the file has changed since the last time we checked
                // this means that we need to act on that change.
                bool fileExists = File.Exists(m_markerFilePath);
                if (m_markerFileExists != fileExists)
                {
                    // Save the result.
                    m_markerFileExists = fileExists;

                    // Take the appropriate action.
                    if (fileExists)
                    {
                        // Enable tracing.
                        EventPipe.Enable(GetConfiguration());
                    }
                    else
                    {
                        // Disable tracing.
                        EventPipe.Disable();
                    }
                }

                // Schedule the timer to run again.
                m_timer.Change(fileExists ? EnabledPollingIntervalMilliseconds : DisabledPollingIntervalMilliseconds, Timeout.Infinite);
            }
            catch { }
        }
Esempio n. 2
0
        private void PollForTracingCommand(object state)
        {
            // Make sure that any transient errors don't cause the listener thread to exit.
            try
            {
                // Check for existence of the config file.
                // If the existence of the file has changed since the last time we checked or the update time has changed
                // this means that we need to act on that change.
                bool fileExists = File.Exists(m_configFilePath);
                if (m_configFileExists != fileExists)
                {
                    // Save the result.
                    m_configFileExists = fileExists;

                    // Take the appropriate action.
                    if (fileExists)
                    {
                        // Enable tracing.
                        // Check for null here because it's possible that the configuration contains a process filter
                        // that doesn't match the current process.  IF this occurs, we should't enable tracing.
                        EventPipeConfiguration config = BuildConfigFromFile(m_configFilePath);
                        if (config != null)
                        {
                            EventPipe.Enable(config);
                        }
                    }
                    else
                    {
                        // Disable tracing.
                        EventPipe.Disable();
                    }
                }

                // Schedule the timer to run again.
                m_timer.Change(fileExists ? EnabledPollingIntervalMilliseconds : DisabledPollingIntervalMilliseconds, Timeout.Infinite);
            }
            catch { }
        }