AutoResetEvent locks main thread

Upgraded to latest premium SDK and now I have problem with follwing code


        private void TriggerThread()
        {
            try
            {
                while (true)
                {
                    if (_pollEnable)
                    {
                        // Poll the trigger input
                        _fireEventSignal.WaitOne(50, false);
                    }
                    else
                    {                        
                        _fireEventSignal.WaitOne();
                    }

                    if (Trigger != null)
                    {
                        if (_triggerPin.Read())
                        {
                            if (_highRequest != null && _lastState != 1)
                            {
                                Trigger(_highRequest);
                            }
                            _lastState = 1;
                        }
                        else
                        {
                            if (_lowRequest != null && _lastState != 0)
                            {
                                Trigger(_lowRequest);
                            }
                            _lastState = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.LogHandler.LogException(ex);
            }
            finally
            {
                if (_fireEventSignal != null)
                    _triggerPin.EnableInterrupt();
            }
        }

Problem is that _fireEventSignal.WaitOne() will freeze the main thread which started the TriggerThread method.
_triggerThread.Start();

I didn’t have this problem in 4.1.

need a complete sample of code which displays your problem to make any worth while comment

this is the calling method


        public TriggerInfo(Cpu.Pin pin)
        {
            _triggerThread = new Thread(new ThreadStart(TriggerThread));
            _triggerThread.Priority = ThreadPriority.Lowest;
            _lastState = -1;
            _pollEnable = false;
            _fireEventSignal = new AutoResetEvent(false);
            
            try
            {
                _triggerPin = new InterruptPort(pin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                _triggerPin.OnInterrupt += new NativeEventHandler(TriggerPinInterrupt);            
                _triggerPin.DisableInterrupt();
                _interruptActivated = true;                
            }
            catch (Exception ex)
            {
                // The pin doesn't support interrupt need to add poll method
                _interruptActivated = false;
            }

            _triggerThread.Start();
        }

I asked for a complete sample. you are giving me snippets. I was going to try to reproduce the problem.

I have to go now, and will not be available. maybe someone else can help you.

I still have problem with this issue in 4.2.

The problem seams to be when I call a method which have a AutoResetEvent.WaitOne inside.

There are two instances of this class and one is called from a thread and the other from a timer.
The deadlock happens when the the first caller is done with WaitOne and leaves the method while the other one is still in WaitOne.
I have a 1000ms timeout in the WaitOne call.

After 60 seconds the G120 restarts in this state.

This problem is realy hard to debugg, when I pause VS in deadlock the G120 is restarts.

sounds like you know enough of the scenario now to be able to create a simple repro project that someone else can try…