Esempio n. 1
0
        public virtual void Unregister()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException(Resources.NotRegisteredMessage);
            }

            // Unregister the service name.
            RegistrationManager.Unregister(_InstanceId, _ServiceHandle);

            // Unregister this server from the context so that it will not receive DDEML callbacks.
            _Context.UnregisterServer(this);

            // Indicate that the service name is no longer registered.
            _ServiceHandle = IntPtr.Zero;
            _InstanceId = 0;

            // Raise the StateChange event.
            if (StateChange != null)
            {
                StateChange(this, EventArgs.Empty);
            }
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_Disposed)
            {
                _Disposed = true;
                if (disposing)
                {
                    if (IsRegistered)
                    {
                        // Unregister the service name.
                        RegistrationManager.Unregister(_InstanceId, _ServiceHandle);

                        // Unregister this server from the context so that it will not receive DDEML callbacks.
                        _Context.UnregisterServer(this);

                        // Indicate that the service name is no longer registered.
                        _ServiceHandle = IntPtr.Zero;
                        _InstanceId = 0;
                        
                        // Raise the StateChange event.
                        foreach (EventHandler handler in StateChange.GetInvocationList())
                        {
                            try
                            {
                                handler(this, EventArgs.Empty);
                            }
                            catch
                            {
                                // Swallow any exception that occurs.
                            }
                        }
                    }
                }
                else 
                {
                    if (IsRegistered) 
                    {
                        // Unregister the service name.
                        RegistrationManager.Unregister(_InstanceId, _ServiceHandle);
                    }
                }
            }
        }