2011年4月28日

[.Net]Object has been disconnected or does not exist at the server.

I am writing a service allows developers to plug their executable into this service, the service shall manage and monitor the status of each plug-in. The service isolate each plug-in by their Category property into a separate AppDomain, each plug-in notify the service of certain events via delegation.

I got '”Object has been disconnected or does not exist at the server” error after certain period of time. Obviously this error occurs because of the remoting proxy has no long connected to the server since they are actually reside in different AppDomain and was expired.

To avoid this, I override the InitializeLifetimeService() method of my base plug-in class as follow to extend the lifetime service.

        public override object InitializeLifetimeService() {
            return null;
        }


To extend the server lifetime lease on each client call, I override InitializeLifetimeService() of the server object, in my case, the PlugInManagerBase class as following.



        public override object InitializeLifetimeService() {
            ILease lease = (ILease)base.InitializeLifetimeService();
            if (lease != null) {
                if (lease.CurrentState == LeaseState.Initial) {
                    lease.InitialLeaseTime = TimeSpan.FromHours(6);
                    lease.RenewOnCallTime = TimeSpan.FromHours(6);
                }
            }
            return lease;
        }

沒有留言:

Blog Archive

About Me