Suspend/Stop Timer

Hi everybody!
Maybe this is a silly problem, but I can't find out any solution....
I start a timerPort (and a timerHandler):

Code Snippet

_timerPort.Post(DateTime.Now);
Activate(Arbiter.Receive(true, _timerPort, TimerHandler));


Is there a way to stop/suspend the Arbiter to handle the _timerPort (and the Timerhandler) ?

Thank you!

Alberto

[577 byte] By [zanetalb] at [2008-1-8]
# 1

Here's a way to do it:

Code Snippet

private Port<DateTime> _timerPort = new Port<DateTime>();

protected override void Start()

{

base.Start();

Activate(Arbiter.Receive(false, _timerPort, TimerHandler));

_timerPort.Post(DateTime.Now);

}

void TimerHandler(DateTime signal)

{

if (signal != DateTime.MinValue)

Activate(Arbiter.Receive(false, _timerPort, TimerHandler));

else

return;

// do something here...

Activate(

Arbiter.Receive(false, TimeoutPort(1000),

delegate(DateTime time)

{

_timerPort.Post(time);

}

)

);

}

void StopTimer()

{

_timerPort.Post(DateTime.MinValue);

}

Notice the persist parameter in the first activation (inside Start method) is false and the TimerHandler checks on each call whether to activate it again or not.

You can also define the timer port as a PortSet like this:

Code Snippet

private PortSet<DateTime, Shutdown> _timerPort = new Port<DateTime, Shutdown>();

And then use an Arbiter.Choice to activate the timer or stop the timer (by not activating it again) when a ShutDown message is received.
OmidK.Rad at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Community...
# 2

Thank you very much!

Alberto

zanetalb at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Community...

Microsoft Robotics Studio

Site Classified