Exemplo n.º 1
0
        /// <summary>
        /// Called when the <see cref="AppDomain.DomainUnload"/> event fires
        /// </summary>
        /// <param name="sender">the <see cref="AppDomain"/> that is exiting</param>
        /// <param name="e">null</param>
        /// <remarks>
        /// <para>
        /// Called when the <see cref="AppDomain.DomainUnload"/> event fires.
        /// </para>
        /// <para>
        /// When the event is triggered the log4net system is <see cref="Shutdown()"/>.
        /// </para>
        /// </remarks>
        private static void OnDomainUnload(object sender, EventArgs e)
        {
            if (ChoFramework.ShutdownRequested)
            {
                return;
            }

            ChoFramework.ShutdownRequested = true;

            if (_shutdownCompleted)
            {
                return;
            }

            try
            {
                Thread.Sleep(1000);  //TODO: To be parameterized

                foreach (Type type in _onDomainUnloadHandlers.ToKeysArray())
                {
                    foreach (MethodInfo methodInfo in _onDomainUnloadHandlers[type])
                    {
                        if (ChoTraceSwitch.Switch.TraceVerbose)
                        {
                            Trace.WriteLine(ChoType.GetMemberAttribute <ChoAppDomainUnloadMethodAttribute>(methodInfo).Description);
                        }
                        //ChoTrace.Info(ChoType.GetMemberAttribute<ChoAppDomainUnloadMethodAttribute>(methodInfo).Description);

                        //using (ChoBufferProfileEx profile = new ChoBufferProfileEx(ChoType.GetMemberAttribute<ChoAppDomainUnloadMethodAttribute>(methodInfo).Description))
                        //{
                        try
                        {
                            ChoType.InvokeMethod(type, methodInfo.Name, null);
                        }
                        catch (Exception) // ex)
                        {
                            //profile.Append(ex);
                        }
                        //}
                    }
                }

                //if (ChoApplication.ApplicationMode == ChoApplicationMode.Console)
                //    ChoFramework.Shutdown();
            }
            finally
            {
                try
                {
                    ChoTrace.FlushAll();
                }
                catch { }
                _shutdownCompleted = true;
            }
        }