How to check if a MarshalByRefObject is valid?

In the VS2010 C # project, we have a class derived from MarshalByRefObject, and we use Activator.GetObject to set it. We use this derived class to communicate with the machine throughout the network.

Sometimes the target machine is turned on and can be configured to ping, but the program we want to talk to does not work, it causes a 30-second wait, followed by an exception. Is there a way to find out if my output is MarshalByRefObject?

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

+4
source share
1 answer

You can try to call the task by the Ping () method and use an explicit timeout for the task ...

Task task = new Task(() => { try { obj.Ping(); } catch {} }); task.Start(); if(!task.Wait(1000)) throw new TimeoutException(); // handle other task exceptions etc 
+4
source

Source: https://habr.com/ru/post/1395811/


All Articles