יום חמישי 21 יולי 2005 18:42
When my .NET remoting client app is disconnected from my server app, how can I reconnect? Here's some example code:
ThreadStart serverMethodToCall = serverObj.SomeMethod;
catch(SocketException ex) // you've been disconnected from the network.
// Pretend I connect to the network once more....
serverMethodToCall(); // still fails, even though I'm reconnected to the network!
Now, to test this, I disable my LAN connection from Windows control panel. The socket exception is thrown as expected. I re-enable my LAN connection, then try calling serverMethodToCall() -- it still fails! Why is this?
יום שלישי 26 יולי 2005 08:39this may be problematic.
when the remote object's lease expires, the object will have no sponsor and the server will mark it for GC. so, even if you get the connection back, it may be pointless -- you will need to create a new object.
my instinctive apporach would be to asynchronously call the method, acquire a WaitHandle and then use a method like WaitOne specifying a timeout. if you get a timeout, attempt to re-instantiate the object and give it another try... I'd also split all of this off into a layer separate from the UI and (if approproate) would design a backup method so that attempts are still being made when the UI app has ended (i.e. I'd persist whatever data I needed to pass up into a file locally and would run a service that tried to perform the function...)