PinCapture

You could use locking and signaling rather than looping constantly.

Something like:


private object _locker = new MicroLock();
private remaining = 0;

void Count(int count)
{
   remaining = count;

   lock(_locker)
   {
      MonitorMicro.Wait(_locker);
   }
}

void _interruptPort_OnInterrupt(uint port, uint state, DateTime timestamp)
{
   lock(_locker)
   {
      remaining--;

      if(remaining <= 0)
      {
          MonitorMicro.Pulse(_locker);
      }
   }
}


Under the hood MonitorMico uses AutoResetEvent, so you could just strip out that code directly.

[url]http://www.fezzer.com/project/162/monitormicro---wait-and-pulse-functionality/[/url]

I’m not sure I get it. When I use you sample code the interrupt still isn’t hit. Presumable because they are on the same thread. When I put the Count in seperate thread my code doesn’t block and I can’t use Thread.Join because it is unavailable when using interruptPorts. Surely my problem should’nt be hard to solve. I just can’t get my head arround it.

All I want is this:


//pseudo code
DoSomethingHere();
GoCountPulsesAndWait(500); //Count pulses and wait for method to return
DoSomethingHere(); //Wait for previous method to finish before doing something else

I’m lost :’(

BurningWheels,

There is a dead lock in that example.

lock(_locker) in the Count methods prevents to pulse the microlock in the interrupt handler.

Have you tried the fix that William suggested earlier in the thread?