diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -14,3 +14,4 @@ Implab.Fx.Test/obj/ Implab.Diagnostics.Interactive/bin/ Implab.Diagnostics.Interactive/obj/ MonoPlay/bin/ +MonoPlay/obj/ diff --git a/Implab/ComponentContainer.cs b/Implab/ComponentContainer.cs new file mode 100644 --- /dev/null +++ b/Implab/ComponentContainer.cs @@ -0,0 +1,48 @@ +using System; +using Implab.Parallels; +using System.Threading; + +namespace Implab { + public class ComponentContainer : IComponentContainer, IDisposable { + static readonly ComponentContainer _appContainer; + + static ComponentContainer() { + _appContainer = new ComponentContainer(); + AppDomain.CurrentDomain.ProcessExit += HandleProcessExit; + } + + public static ComponentContainer Global { + get { + return _appContainer; + } + } + + bool m_disposed; + readonly MTQueue m_components = new MTQueue(); + + public void Add(IDisposable item) { + Safe.ArgumentNotNull(item, "item"); + Thread.MemoryBarrier(); + if (m_disposed) { + item.Dispose(); + } else { + m_components.Enqueue(item); + if (m_disposed && m_components.TryDequeue(out item)) + item.Dispose(); + } + } + + public void Dispose() { + m_disposed = true; + IDisposable item; + while (m_components.TryDequeue(out item)) + item.Dispose(); + } + + static void HandleProcessExit (object sender, EventArgs e) + { + _appContainer.Dispose(); + } + } +} + diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -146,10 +146,10 @@ - + diff --git a/Implab/MTComponentContainer.cs b/Implab/MTComponentContainer.cs deleted file mode 100644 --- a/Implab/MTComponentContainer.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Implab.Parallels; -using System.Threading; - -namespace Implab { - public class MTComponentContainer : IComponentContainer, IDisposable { - static readonly MTComponentContainer _appContainer; - - static MTComponentContainer() { - _appContainer = new MTComponentContainer(); - AppDomain.CurrentDomain.ProcessExit += HandleProcessExit; - } - - public static MTComponentContainer AppContainer { - get { - return _appContainer; - } - } - - bool m_disposed; - readonly MTQueue m_components = new MTQueue(); - - public void Add(IDisposable item) { - Safe.ArgumentNotNull(item, "item"); - Thread.MemoryBarrier(); - if (m_disposed) { - item.Dispose(); - } else { - m_components.Enqueue(item); - if (m_disposed && m_components.TryDequeue(out item)) - item.Dispose(); - } - } - - public void Dispose() { - m_disposed = true; - IDisposable item; - while (m_components.TryDequeue(out item)) - item.Dispose(); - } - - static void HandleProcessExit (object sender, EventArgs e) - { - _appContainer.Dispose(); - } - } -} -