コード例 #1
0
        /// <summary>
        /// Creates a new Thread that handles processing of Input/Output with the ELM327.
        /// </summary>
        private void SpawnIOThread()
        {
            // Variables
            IHandler currentHandler;
            string   buffer = "";

            // Log starting of IO Thread
            log.Info("Starting ELM327 IO Thread...");

            // Main Loop
            while (_continueRunningIOThread)
            {
                // Get the next handler
                if (!(_monitoredHandlers.IsEmpty) && (_monitoredHandlers.TryDequeue(out currentHandler)))
                {
                    // Set the ECU filter
                    _protocol.SelectedEcuFilter = _selectedEcuFilter;

                    // Have the current Protocol handler execute this handler's request
                    _protocol.Execute(currentHandler);

                    // If this handler still has registered listeners after its execution, enqueue it again
                    if (currentHandler.HasRegisteredListeners || currentHandler.HasRegisteredSingleListeners)
                    {
                        _monitoredHandlers.Enqueue(currentHandler);
                    }
                }
            }

            // Log exiting of IO Thread
            log.Info("Exiting ELM327 IO Thread...");
        }