Using Timed Action to retry ConnectWorker

Oct 20, 2012 at 12:16 AM

Hi Thomas,

I've just noticed the new version (better late than never!) and am interested in using the Timed Action to keep retrying t0 connect to a worker if the worker is not available (has not been started). I've used the same code as you've published but 1) My connect never starts 2) How do I stop the rest of the method from running (after the .Invoke()) whilst waiting for the retry (i.e. block the rest of the method till there is a connection established)

I have something like this:



var timedAction = _space.CreateTimedAction(



() => {

_worker = _space.ConnectWorker<



return XcoTimedAction.Continuation.Stop;



















// SiAuto.Main.LogMessage("Attempting to connect to dispatcher");


// _worker = _space.ConnectWorker<PDispatcherWorker>(dispatcherAddress);


// return XcoTimedAction.Continuation.Stop;




//catch (System.Exception ex)




// SiAuto.Main.LogMessage("Failed to connect to dispatcher. Retrying");


// return XcoTimedAction.Continuation.Reschedule;





timedAction.Invoke(); of code should run once we have a connection

 Any help gratefully received

Kind regards


Oct 22, 2012 at 9:24 AM

Hi Mike,

If you want to reschedule the action so often until a connection is established, then I would say that the second variant is the right one. However, I don't know if a TimedAction is really what you are looking for if you want to synchronously wait until the connection has been made. The TimedAction runs asynchronously, so if you want to wait on something you would e.g. need to use a ManualResetEvent. But if you do that, it would be easier to just make a loop with Thread.Sleep() between the connection tries, that runs synchronously in your code.

If you don't actually need to wait synchronously you could use a port to continue after the connection has been established. Something like:

var continuationPort = space.Receive<PDispatcherWorker>(w => ... do something with connected worker ...);

and within the timed action:

_worker = _space.ConnectWorker<PDispatcherWorker>(dispatcherAddress);
return XcoTimedAction.Continuation.Stop;

Hope I could help you!

Best Regards