I use execution constraints in my state machine architecture to make sure no state hangs up and stops the whole mess. They work really well mostly because (at least in my understanding) they run in a separate thread so almost no matter how badly I screw up a state, the execution constraint will fire and I can deal with the issue. Now I’d like to add a second execution constraint that runs simultaneously with the state execution constraint that makes sure the whole “mission” completes within a specified amount of time. Unfortunately, I don’t see a way to differentiate the 2 types of execution constraints and since I have to react differently to each type, I’m kind of stuck. The execution constraint shows a “message” property in the debugger that seems perfect for my needs but it isn’t documented in MSDN and I haven’t been able to figure out how to use it. Any suggestions will be greatly appreciated.
Thanks - Gene
PS Here’s a simple test program I’m using to see if I can make this work and a snapshot of what the debugger shows for the currentException.
using System;
using Microsoft.SPOT;
using System.Threading;
namespace missionExecutionConstraintTest
{
public class Program
{
public static void Main()
{
bool missionRun = true;
Debug.Print("ProgramStarted");
ExecutionConstraint.Install(10000, 0); //10 second mission EC
try
{
while (missionRun)
{
try
{
ExecutionConstraint.Install(5000, 0); //5 second state EC
for (int i = 0; i < 1000; i++)
{
Debug.Print("i = " + i.ToString());
Thread.Sleep(500);
}
}
catch (Exception currentException)
{
if (currentException is ConstraintException)
Debug.Print("State Constraint Exception");
}
}
}
catch(Exception currentException)
{
if (currentException is ConstraintException)
Debug.Print("Mission Constraint Exception");
}
}
}
}