Ejemplo n.º 1
0
        /// <summary>
        /// Fires the BroadcastReceiverHasBeenExcluded event and detach the sponsor from the specified receiver.
        /// </summary>
        /// <param name="state">The receiver being excluded.</param>
        public void DeleteSponsorFromTheObjectAndFireEvent(object state)
        {
            ReceiverInfo       receiverInfo       = (ReceiverInfo)state;
            MarshalByRefObject marshalByRefObject = (MarshalByRefObject)receiverInfo.MbrObject;

            // fire the event
            try
            {
                if (this.BroadcastReceiverHasBeenExcluded != null)
                {
                    this.BroadcastReceiverHasBeenExcluded(marshalByRefObject, receiverInfo);
                }
            }
            catch
            {
                // ignore all exceptions
            }

            // detach sponsor
            try
            {
                ILease lease = (ILease)RemotingServices.GetLifetimeService(marshalByRefObject);
                if (lease != null)
                {
                    lease.Unregister(this.GlobalSponsor);
                }
            }
            catch
            {
                // ignore all exceptions
            }
        }
Ejemplo n.º 2
0
    public void Dispose()
    {
        MarshalByRefObject mbr   = (MarshalByRefObject)controller;
        ILease             lease = mbr.GetLifetimeService() as ILease;

        lease.Unregister(this);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Destroys the AppDomain, if one was created.
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            // If this is a managed object, call its Dispose method.
            if (disposing)
            {
                if (mObj is IDisposable)
                {
                    ((IDisposable)mObj).Dispose();
                }
            }

            // Remove ourselves from the lifetime service.
            object leaseObj = mObj.GetLifetimeService();

            if (leaseObj is ILease)
            {
                ILease lease = (ILease)leaseObj;
                lease.Unregister(this);
            }

            mDisposed = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Disposes the sponsor and the instance it wraps.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (disposing)
                {
                    if (Instance is IDisposable)
                    {
                        ((IDisposable)Instance).Dispose();
                    }

                    if (Instance is MarshalByRefObject)
                    {
                        object lifetimeService = RemotingServices.GetLifetimeService((MarshalByRefObject)(object)Instance);
                        if (lifetimeService is ILease)
                        {
                            ILease lease = (ILease)lifetimeService;
                            lease.Unregister(this);
                        }
                    }
                }

                Instance   = null;
                IsDisposed = true;
            }
        }
 public void Dispose()
 {
     if (_lease != null)
     {
         _lease.Unregister(this);
     }
 }
Ejemplo n.º 6
0
        private void OnClosed(object sender, EventArgs e)
        {
            //Unegister the sponsor
            ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Obj);

            lease.Unregister(m_Sponsor);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Indicates to the TaskHost that it is no longer needed.
        /// Called by TaskBuilder when the task using the EngineProxy is done.
        /// </summary>
        internal void MarkAsInactive()
        {
            lock (_callbackMonitor)
            {
                VerifyActiveProxy();
                _activeProxy = false;

                // Since the task has a pointer to this class it may store it in a static field. Null out
                // internal data so the leak of this object doesn't lead to a major memory leak.
                _host         = null;
                _requestEntry = null;

                // Don't bother clearing the tiny task location
                _taskLoggingContext    = null;
                _targetBuilderCallback = null;

                // Clear out the sponsor (who is responsible for keeping the EngineProxy remoting lease alive until the task is done)
                // this will be null if the engine proxy was never sent across an AppDomain boundary.
                if (_sponsor != null)
                {
                    ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

                    if (lease != null)
                    {
                        lease.Unregister(_sponsor);
                    }

                    _sponsor.Close();
                    _sponsor = null;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Indicates to the EngineProxy that it is no longer needed.
        /// Called by TaskEngine when the task using the EngineProxy is done.
        /// </summary>
        internal void MarkAsInActive()
        {
            activeProxy = false;

            // Since the task has a pointer to this class it may store it in a static field. Null out
            // internal data so the leak of this object doesn't lead to a major memory leak.
            loggingServices   = null;
            parentModule      = null;
            buildEventContext = null;

            // Clear out the sponsor (who is responsible for keeping the EngineProxy remoting lease alive until the task is done)
            // this will be null if the engineproxy was never sent accross an appdomain boundry.
            if (sponsor != null)
            {
                ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

                if (lease != null)
                {
                    lease.Unregister(sponsor);
                }

                sponsor.Close();
                sponsor = null;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Destroys the AppDomain, if one was created.
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            // If this is a managed object, call its Dispose method.
            if (disposing)
            {
                if (mObj is IDisposable)
                {
                    ((IDisposable)mObj).Dispose();
                }
            }

            // Remove ourselves from the lifetime service.
            object leaseObj;

            try {
                leaseObj = mObj.GetLifetimeService();
            } catch (Exception ex) {
                Console.WriteLine("WARNING: GetLifetimeService failed: " + ex.Message);
                leaseObj = null;
            }
            if (leaseObj is ILease)
            {
                ILease lease = (ILease)leaseObj;
                lease.Unregister(this);
            }

            mDisposed = true;
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     if (_registered)
     {
         _proxy.Unregister(this);
         _registered = false;
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing && !_disposed)
     {
         _disposed = true;
         _lease.Unregister(this);
         _runningApp.Dispose();
     }
 }
Ejemplo n.º 12
0
 public void Close()
 {
     foreach (MarshalByRefObject obj in registered_objects.Values)
     {
         ILease lease = obj.GetLifetimeService() as ILease;
         lease.Unregister(this);
     }
     registered_objects.Clear();
 }
Ejemplo n.º 13
0
 /// <summary>Empties the list objects registered with the current <see cref="T:System.Runtime.Remoting.Lifetime.ClientSponsor" />.</summary>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
 /// </PermissionSet>
 public void Close()
 {
     foreach (object obj in this.registered_objects.Values)
     {
         MarshalByRefObject marshalByRefObject = (MarshalByRefObject)obj;
         ILease             lease = marshalByRefObject.GetLifetimeService() as ILease;
         lease.Unregister(this);
     }
     this.registered_objects.Clear();
 }
Ejemplo n.º 14
0
        public void Unregister(MarshalByRefObject obj)
        {
            ILease lease = (ILease)RemotingServices.GetLifetimeService(obj);

            Debug.Assert(lease.CurrentState == LeaseState.Active);
            lease.Unregister(this);
            lock (this._lock) {
                this._leaseList.Remove(lease);
                Logger.Debug(this, "Stopped sponsoring lease #" + lease.GetHashCode() + " for proxy to " + obj.GetType().Name + ", id = #" + obj.GetHashCode() + ", url = " + RemotingServices.GetObjectUri(obj));
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Closes the connection.
 /// </summary>
 private void CloseConnectionInternal()
 {
     if (this._connection != null)
     {
         this._connection.Close();
         ILease lease = (ILease)RemotingServices.GetLifetimeService(this._connection);
         lease.Unregister(this._connectionSponsor);
         this._connection        = null;
         this._connectionSponsor = null;
     }
 }
Ejemplo n.º 16
0
        public void Unregister(MarshalByRefObject obj)
        {
            if (!registered_objects.ContainsKey(obj))
            {
                return;
            }
            ILease lease = obj.GetLifetimeService() as ILease;

            lease.Unregister(this);
            registered_objects.Remove(obj);
        }
Ejemplo n.º 17
0
        public void Unregister(MarshalByRefObject obj)
        {
            ILease lease = (ILease)RemotingServices.GetLifetimeService(obj);

            Debug.Assert(lease.CurrentState == LeaseState.Active);

            lease.Unregister(this);
            lock (this)
            {
                leaseObjects.Remove(lease);
            }
        }
Ejemplo n.º 18
0
        public void Unregister(MarshalByRefObject obj)
        {
            ILease lease = (ILease)null;

            lock (this.sponsorTable)
                lease = (ILease)this.sponsorTable[(object)obj];
            if (lease == null)
            {
                return;
            }
            lease.Unregister((ISponsor)this);
        }
Ejemplo n.º 19
0
        public void Unregister(MarshalByRefObject obj)
        {
            ILease lease = null;

            lock (this.sponsorTable)
            {
                lease = (ILease)this.sponsorTable[obj];
            }
            if (lease != null)
            {
                lease.Unregister(this);
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Releases lifetime service.
 /// </summary>
 public void Dispose()
 {
     if (!this.IsDisposed())
     {
         this.disposed = true;
         GC.SuppressFinalize(this);
         ILease lease = GetLifetimeService() as ILease;
         if (lease != null)
         {
             lease.Unregister(this);
         }
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or
        /// resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// </remarks>
        private void Dispose(bool disposing)
        {
            ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

            if (lease != null)
            {
                lease.Unregister(_sponsor);
            }
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }
        }
Ejemplo n.º 22
0
 public void UnregisterAll()
 {
     lock (this._lock) {
         int index = 0;
         while (this._leaseList.Count > 0)
         {
             ILease lease = this._leaseList[index];
             lease.Unregister(this);
             this._leaseList.RemoveAt(index);
             Logger.Debug(this, "Removevd lease #" + lease.GetHashCode());
             index++;
         }
     }
 }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            String filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            RemotingConfiguration.Configure(filename);

            IRemoteFactory fact = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));
            IRemoteObject  cao  = fact.CreateInstance();

            IRemoteSponsorFactory sf = (IRemoteSponsorFactory)RemotingHelper.CreateProxy(typeof(IRemoteSponsorFactory));
            InstanceSponsor       sp = sf.CreateSponsor();

            EnsureKeepAlive keepalive = new EnsureKeepAlive(sp);

            ILease le = (ILease)((MarshalByRefObject)cao).GetLifetimeService();

            le.Register(sp);

            try
            {
                Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in first call\n{0}", e.Message);
            }

            Console.WriteLine("{0} CLIENT: Sleeping for 6 seconds", DateTime.Now);
            Thread.Sleep(6000);

            try
            {
                Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in second call\n{0}", e.Message);
            }

            Console.WriteLine("{0} CLIENT: Unregistering sponsor", DateTime.Now);
            le.Unregister(sp);
            keepalive.StopKeepAlive();

            Console.WriteLine("Finished ... press <return> to exit");
            Console.ReadLine();
            Console.ReadLine();
        }
Ejemplo n.º 24
0
        [System.Security.SecurityCritical]  // auto-generated
        public void Unregister(MarshalByRefObject obj)
        {
            BCLDebug.Trace("REMOTE", "ClientSponsor Unregister " + obj);

            ILease lease = null;

            lock (sponsorTable)
            {
                lease = (ILease)sponsorTable[obj];
            }
            if (lease != null)
            {
                lease.Unregister(this);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Destroys the Sponsor, if one was created.
        /// </summary>
        /// <param name="disposing">True if called from Dispose(), false if from finalizer.</param>
        protected virtual void Dispose(bool disposing) {
            if (mDisposed) {
                return;
            }
            Debug.WriteLine("Sponsor.Dispose(disposing=" + disposing + ")");

            // If this is a managed object, call its Dispose method.
            if (disposing) {
                if (mObj is IDisposable) {
                    ((IDisposable)mObj).Dispose();
                }
            }

            // Remove ourselves from the lifetime service.
            // NOTE: if you see this blowing up at app shutdown, it's because you didn't
            //   call Dispose() on the DomainManager.
            object leaseObj;
            try {
                leaseObj = mObj.GetLifetimeService();
            } catch (Exception ex) {
                // This seems to happen when we shut down without having disposed of the
                // AppDomain, probably when a Sponsor's finalizer runs before the
                // DomainManager's finalizer.  Sometimes it also happens when you seem to
                // be doing everything right, though this seems to correspond with a lack
                // of lease renewal messages (i.e. something is really wrong as the other end).
                //
                // I think failures here can be ignored, since it's just failure to clean up
                // something that doesn't exist.
                //
                // Sometimes it's:
                //  RemotingException: Object '---' has been disconnected or does not exist at the server.
                Debug.WriteLine("WARNING: GetLifetimeService failed: " + ex.Message);
                leaseObj = null;
            }
            if (leaseObj is ILease) {
                ILease lease = (ILease)leaseObj;
                try {
                    lease.Unregister(this);
                } catch (InvalidOperationException ex) {
                    // TODO(someday): not expected -- why did this start happening?  (Might
                    // be related to the timer hack not being enabled during early stages of
                    // WPF port?  Seems to have stopped.)
                    Debug.WriteLine("WARNING: lease.Unregister threw " + ex);
                }
            }

            mDisposed = true;
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("Cliente.exe.config", false);
            Servicio servicioProxy = new Servicio();
            ILease   concesion     = (ILease)RemotingServices.GetLifetimeService(servicioProxy);
            Esponsor esponsor      = new Esponsor();

            concesion.Register(esponsor);

            gestionar(servicioProxy);

            Console.WriteLine("Pulsa Enter para salir");
            Console.ReadLine();

            concesion.Unregister(esponsor);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 撤销远程接口
 /// </summary>
 virtual public void Dispose()
 {
     if (remoteObject != null)
     {
         try
         {
             MarshalByRefObject _mo   = remoteObject as MarshalByRefObject;
             ILease             lease = (ILease)_mo.GetLifetimeService();
             lease.Unregister(sponsor);
         }
         catch (Exception e)
         {
             string errmsg = e.Message;
         }
     }
 }
Ejemplo n.º 28
0
        public void Unregister(object obj)
        {
            MarshalByRefObject remoteObject = obj as MarshalByRefObject;

            if (remoteObject == null)
            {
                return;
            }
            ILease lease = RemotingServices.GetLifetimeService(remoteObject) as ILease;

            if (lease == null)
            {
                return;
            }
            lease.Unregister(this);
        }
Ejemplo n.º 29
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!this.IsDisposed())
                {
                    this.disposed = true;

                    ILease lease = this.GetLifetimeService() as ILease;
                    if (lease != null)
                    {
                        lease.Unregister(this);
                    }
                }
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// 注销远程对象接口
 /// </summary>
 /// <param name="_interfaceName"></param>
 /// <returns></returns>
 public static void DiscardRemotingInterface(string _interfaceName)
 {
     if (serverObjectLib.ContainsKey(_interfaceName))
     {
         object _icsObject = serverObjectLib[_interfaceName];
         try
         {
             MarshalByRefObject _mo   = _icsObject as MarshalByRefObject;
             ILease             lease = (ILease)_mo.GetLifetimeService();
             lease.Unregister(sponsorLib[_interfaceName]);
         }
         catch (Exception e)
         {
             string errmsg = e.Message;
         }
         sponsorLib.Remove(_interfaceName);
         serverObjectLib.Remove(_interfaceName);
     }
 }