Question

In a VS2010 C# project we have a class derived from a MarshalByRefObject and we use Activator.GetObject to set it. We are using this derived class to talk to a machine across the network.

Sometimes the target machine is on and able to be pinged but it isn't running the program we want to talk to, this causes a 30 second wait followed by an exception. Is there a way to tell if my derived MarshalByRefObject is valid?

Currently a try/catch is handling this situation, but the 30 second wait is not acceptable.

Was it helpful?

Solution

You could try having a Task call a Ping() method, and use the explicit timeout on the task...

Task task = new Task(() => { try { obj.Ping(); } catch {} });
task.Start();
if(!task.Wait(1000)) throw new TimeoutException();
// handle other task exceptions etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top