1 // Copyright (c) 2017 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;
15 public class DisposeQueue
17 private static readonly DisposeQueue _disposableQueue = new DisposeQueue();
18 private List<IDisposable> _disposables = new List<IDisposable>();
19 private System.Object _listLock = new object();
20 private EventThreadCallback _eventThreadCallback;
21 private EventThreadCallback.CallbackDelegate _disposeQueueProcessDisposablesDelegate;
23 private DisposeQueue()
31 public static DisposeQueue Instance
33 get { return _disposableQueue; }
36 public void Initialize()
38 _disposeQueueProcessDisposablesDelegate = new EventThreadCallback.CallbackDelegate(ProcessDisposables);
39 _eventThreadCallback = new EventThreadCallback(_disposeQueueProcessDisposablesDelegate);
42 public void Add(IDisposable disposable)
46 _disposables.Add(disposable);
49 _eventThreadCallback.Trigger();
52 private void ProcessDisposables()
56 foreach (IDisposable disposable in _disposables)