示例#1
0
        private void NotifyImportSatisfied()
        {
            if (this._invokeImportsSatisfied && !this._invokingImportsSatisfied)
            {
                IPartImportsSatisfiedNotification notify = this.GetInstanceActivatingIfNeeded() as IPartImportsSatisfiedNotification;
                if (notify != null)
                {
                    try
                    {
                        // Reentrancy on composition notifications is allowed, so set this first to avoid
                        // an infinte loop of notifications.
                        this._invokingImportsSatisfied = true;

                        notify.OnImportsSatisfied();
                    }
                    catch (Exception exception)
                    {
                        throw new ComposablePartException(
                                  String.Format(CultureInfo.CurrentCulture,
                                                Strings.ReflectionModel_PartOnImportsSatisfiedThrewException,
                                                Definition.GetPartType().FullName),
                                  Definition.ToElement(),
                                  exception);
                    }
                    finally
                    {
                        this._invokingImportsSatisfied = false;
                    }

                    this._invokeImportsSatisfied = false;
                }
            }
        }
        private void NotifyImportSatisfied()
        {
            if (_invokeImportsSatisfied)
            {
                IPartImportsSatisfiedNotification notify = GetInstanceActivatingIfNeeded() as IPartImportsSatisfiedNotification;

                lock (_lock)
                {
                    if (!_invokeImportsSatisfied)
                    {
                        //Already notified on another thread
                        return;
                    }
                    _invokeImportsSatisfied = false;
                }

                if (notify != null)
                {
                    try
                    {
                        notify.OnImportsSatisfied();
                    }
                    catch (Exception exception)
                    {
                        throw new ComposablePartException(
                                  string.Format(CultureInfo.CurrentCulture,
                                                SR.ReflectionModel_PartOnImportsSatisfiedThrewException,
                                                Definition.GetPartType().FullName),
                                  Definition.ToElement(),
                                  exception);
                    }
                }
            }
        }