public void Dispose() { if (_IsDisposed) { return; } _IsDisposed = true; if (_WorkerThread != null) { var workItems = _WorkerThread.WorkItems; _WorkerThread.Dispose(); _WorkerThread = null; IWorkItem <T> wi; while (workItems.TryDequeue(out wi)) { wi.Dispose(); } } BTree.Dispose(); foreach (var index in Indices.Values) { index.Dispose(); } Indices.Clear(); if (OwnsStorage) { Storage.Dispose(); } }
/// <summary> /// Queues a work item into the tangle's work queue. Work items in the queue are processed sequentially in order to prevent corruption of internal data structures. /// </summary> /// <typeparam name="U">The type of the work item's result, if any.</typeparam> /// <param name="workItem">The work item.</param> /// <returns>A future that will contain the result of the work item once it is complete.</returns> internal Future <U> QueueWorkItem <U> (IWorkItemWithFuture <T, U> workItem) { if (_IsDisposed) { throw new ObjectDisposedException("Tangle"); } var future = workItem.Future; if (_WorkerThread == null) { _WorkerThread = new Squared.Task.Internal.WorkerThread <ConcurrentQueue <IWorkItem <T> > >( WorkerThreadFunc, ThreadPriority.Normal, String.Format("Tangle<{0}> Worker", typeof(T).ToString()) ); } _WorkerThread.WorkItems.Enqueue(workItem); _WorkerThread.Wake(); return(future); }