##// END OF EJS Templates
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation

File last commit:

r119:2573b562e328 v2
r138:f75cfa58e3d4 v2
Show More
ComponentContainer.cs
48 lines | 1.3 KiB | text/x-csharp | CSharpLexer
/ Implab / ComponentContainer.cs
cin
minor refactoring
r116 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;
cin
Promises rewritten, added improved version of AsyncQueue
r119 readonly AsyncQueue<IDisposable> m_components = new AsyncQueue<IDisposable>();
cin
minor refactoring
r116
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();
}
}
}