Example #1
0
        private void Poll(object state)
        {
            try
            {
                if (_pin.Read() == BinaryState.Low)
                {
                    InterruptDetected?.Invoke(this, EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error while polling interrupt pin '" + _pin + "'");

                // Ensure that a persistent error will not flood the trace.
                _timer.Change(2000, Timeout.Infinite);
            }
            finally
            {
                _timer.Change(10, Timeout.Infinite);
            }
        }
Example #2
0
        public async Task PollAsync()
        {
            while (true)
            {
                try
                {
                    if (_pin.Read() == BinaryState.Low)
                    {
                        InterruptDetected?.Invoke(this, EventArgs.Empty);
                    }

                    await Task.Delay(10);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while polling interrupt pin '" + _pin + "'");

                    // Ensure that a persistent error will not flood the trace.
                    await Task.Delay(2000);
                }
            }
        }