1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // PROPRIETARY/CONFIDENTIAL
3 // This software is the confidential and proprietary
4 // information of SAMSUNG ELECTRONICS ("Confidential Information"). You shall
5 // not disclose such Confidential Information and shall use it only in
6 // accordance with the terms of the license agreement you entered into with
7 // SAMSUNG ELECTRONICS.
11 using System.Collections.Generic;
16 internal class DisposeQueue
18 private static readonly DisposeQueue _disposableQueue = new DisposeQueue();
19 private List<IDisposable> _disposables = new List<IDisposable>();
20 private System.Object _listLock = new object();
21 private EventThreadCallback _eventThreadCallback;
22 private EventThreadCallback.CallbackDelegate _disposeQueueProcessDisposablesDelegate;
24 private DisposeQueue()
32 public static DisposeQueue Instance
34 get { return _disposableQueue; }
37 public void Initialize()
39 _disposeQueueProcessDisposablesDelegate = new EventThreadCallback.CallbackDelegate(ProcessDisposables);
40 _eventThreadCallback = new EventThreadCallback(_disposeQueueProcessDisposablesDelegate);
43 public void Add(IDisposable disposable)
47 _disposables.Add(disposable);
50 if (_eventThreadCallback != null)
52 _eventThreadCallback.Trigger();
56 private void ProcessDisposables()
60 foreach (IDisposable disposable in _disposables)