1 changed file
Shell | ||
ThreadSafeListWithLock.cs | ||
ThreadSafeListWithLock.cs
/Shell/ThreadSafeListWithLock.cs-110+110/Shell/ThreadSafeListWithLock.cs
Add comment 1 Minus using System;
Add comment 2 Minus using System.Collections.Generic;
Add comment 3 Minus using System.Linq;
Add comment 4 Minus using System.Text;
Add comment 5 Minus using System.Threading;
Add comment 6 Minus using System.Threading.Tasks;
Add comment 1 Plus //using System;
Add comment 2 Plus //using System.Collections.Generic;
Add comment 3 Plus //using System.Linq;
Add comment 4 Plus //using System.Text;
Add comment 5 Plus //using System.Threading;
Add comment 6 Plus //using System.Threading.Tasks;
Add comment 7
Add comment 8 Minus namespace BExplorer.Shell {
Add comment 9 Minus public class ThreadSafeListWithLock<T> : IList<T> {
Add comment 10 Minus private List<T> internalList;
Add comment 8 Plus //namespace BExplorer.Shell {
Add comment 9 Plus // public class ThreadSafeListWithLock<T> : IList<T> {
Add comment 10 Plus // private List<T> internalList;
Add comment 11
Add comment 12 Minus private readonly object lockList = new object();
Add comment 12 Plus // private readonly object lockList = new object();
Add comment 13
Add comment 14 Minus public ThreadSafeListWithLock() {
Add comment 15 Minus internalList = new List<T>();
Add comment 16 Minus }
Add comment 14 Plus // public ThreadSafeListWithLock() {
Add comment 15 Plus // internalList = new List<T>();
Add comment 16 Plus // }
Add comment 17
Add comment 18 Minus // Other Elements of IList implementation
Add comment 18 Plus // // Other Elements of IList implementation
Add comment 19
Add comment 20 Minus public IEnumerator<T> GetEnumerator() {
Add comment 21 Minus return Clone().GetEnumerator();
Add comment 22 Minus }
Add comment 20 Plus // public IEnumerator<T> GetEnumerator() {
Add comment 21 Plus // return Clone().GetEnumerator();
Add comment 22 Plus // }
Add comment 23
Add comment 24 Minus System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
Add comment 25 Minus return Clone().GetEnumerator();
Add comment 26 Minus }
Add comment 24 Plus // System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
Add comment 25 Plus // return Clone().GetEnumerator();
Add comment 26 Plus // }
Add comment 27
Add comment 28 Minus public List<T> Clone() {
Add comment 29 Minus List<T> threadClonedList = new List<T>();
Add comment 28 Plus // public List<T> Clone() {
Add comment 29 Plus // List<T> threadClonedList = new List<T>();
Add comment 30
Add comment 31 Minus lock (lockList) {
Add comment 32 Minus internalList.ForEach(element => { threadClonedList.Add(element); });
Add comment 33 Minus }
Add comment 31 Plus // lock (lockList) {
Add comment 32 Plus // internalList.ForEach(element => { threadClonedList.Add(element); });
Add comment 33 Plus // }
Add comment 34
Add comment 35 Minus return (threadClonedList);
Add comment 36 Minus }
Add comment 35 Plus // return (threadClonedList);
Add comment 36 Plus // }
Add comment 37
Add comment 38 Minus public void Add(T item) {
Add comment 39 Minus lock (lockList) {
Add comment 40 Minus internalList.Add(item);
Add comment 41 Minus }
Add comment 42 Minus }
Add comment 38 Plus // public void Add(T item) {
Add comment 39 Plus // lock (lockList) {
Add comment 40 Plus // internalList.Add(item);
Add comment 41 Plus // }
Add comment 42 Plus // }
Add comment 43
Add comment 44 Minus public void AddRange(T[] items) {
Add comment 45 Minus lock (lockList) {
Add comment 46 Minus internalList.AddRange(items);
Add comment 47 Minus }
Add comment 48 Minus }
Add comment 44 Plus // public void AddRange(T[] items) {
Add comment 45 Plus // lock (lockList) {
Add comment 46 Plus // internalList.AddRange(items);
Add comment 47 Plus // }
Add comment 48 Plus // }
Add comment 49
Add comment 50 Minus public bool Remove(T item) {
Add comment 51 Minus bool isRemoved;
Add comment 50 Plus // public bool Remove(T item) {
Add comment 51 Plus // bool isRemoved;
Add comment 52
Add comment 53 Minus lock (lockList) {
Add comment 54 Minus isRemoved = internalList.Remove(item);
Add comment 55 Minus }
Add comment 53 Plus // lock (lockList) {
Add comment 54 Plus // isRemoved = internalList.Remove(item);
Add comment 55 Plus // }
Add comment 56
Add comment 57 Minus return (isRemoved);
Add comment 58 Minus }
Add comment 57 Plus // return (isRemoved);
Add comment 58 Plus // }
Add comment 59
Add comment 60 Minus public void Clear() {
Add comment 61 Minus lock (lockList) {
Add comment 62 Minus internalList.Clear();
Add comment 63 Minus }
Add comment 64 Minus }
Add comment 60 Plus // public void Clear() {
Add comment 61 Plus // lock (lockList) {
Add comment 62 Plus // internalList.Clear();
Add comment 63 Plus // }
Add comment 64 Plus // }
Add comment 65
Add comment 66 Minus public bool Contains(T item) {
Add comment 67 Minus bool containsItem;
Add comment 66 Plus // public bool Contains(T item) {
Add comment 67 Plus // bool containsItem;
Add comment 68
Add comment 69 Minus lock (lockList) {
Add comment 70 Minus containsItem = internalList.Contains(item);
Add comment 71 Minus }
Add comment 69 Plus // lock (lockList) {
Add comment 70 Plus // containsItem = internalList.Contains(item);
Add comment 71 Plus // }
Add comment 72
Add comment 73 Minus return (containsItem);
Add comment 74 Minus }
Add comment 73 Plus // return (containsItem);
Add comment 74 Plus // }
Add comment 75
Add comment 76 Minus public void CopyTo(T[] array, int arrayIndex) {
Add comment 77 Minus lock (lockList) {
Add comment 78 Minus internalList.CopyTo(array, arrayIndex);
Add comment 79 Minus }
Add comment 80 Minus }
Add comment 76 Plus // public void CopyTo(T[] array, int arrayIndex) {
Add comment 77 Plus // lock (lockList) {
Add comment 78 Plus // internalList.CopyTo(array, arrayIndex);
Add comment 79 Plus // }
Add comment 80 Plus // }
Add comment 81
Add comment 82 Minus public int Count
Add comment 83 Minus {
Add comment 84 Minus get
Add comment 85 Minus {
Add comment 86 Minus int count;
Add comment 82 Plus // public int Count
Add comment 83 Plus // {
Add comment 84 Plus // get
Add comment 85 Plus // {
Add comment 86 Plus // int count;
Add comment 87
Add comment 88 Minus lock ((lockList)) {
Add comment 89 Minus count = internalList.Count;
Add comment 90 Minus }
Add comment 88 Plus // lock ((lockList)) {
Add comment 89 Plus // count = internalList.Count;
Add comment 90 Plus // }
Add comment 91
Add comment 92 Minus return (count);
Add comment 93 Minus }
Add comment 94 Minus }
Add comment 92 Plus // return (count);
Add comment 93 Plus // }
Add comment 94 Plus // }
Add comment 95
Add comment 96 Minus public bool IsReadOnly
Add comment 97 Minus {
Add comment 98 Minus get { return false; }
Add comment 99 Minus }
Add comment 96 Plus // public bool IsReadOnly
Add comment 97 Plus // {
Add comment 98 Plus // get { return false; }
Add comment 99 Plus // }
Add comment 100
Add comment 101 Minus public int IndexOf(T item) {
Add comment 102 Minus int itemIndex;
Add comment 101 Plus // public int IndexOf(T item) {
Add comment 102 Plus // int itemIndex;
Add comment 103
Add comment 104 Minus lock ((lockList)) {
Add comment 105 Minus itemIndex = internalList.IndexOf(item);
Add comment 106 Minus }
Add comment 104 Plus // lock ((lockList)) {
Add comment 105 Plus // itemIndex = internalList.IndexOf(item);
Add comment 106 Plus // }
Add comment 107
Add comment 108 Minus return (itemIndex);
Add comment 109 Minus }
Add comment 108 Plus // return (itemIndex);
Add comment 109 Plus // }
Add comment 110
Add comment 111 Minus public void Insert(int index, T item) {
Add comment 112 Minus lock ((lockList)) {
Add comment 113 Minus internalList.Insert(index, item);
Add comment 114 Minus }
Add comment 115 Minus }
Add comment 111 Plus // public void Insert(int index, T item) {
Add comment 112 Plus // lock ((lockList)) {
Add comment 113 Plus // internalList.Insert(index, item);
Add comment 114 Plus // }
Add comment 115 Plus // }
Add comment 116
Add comment 117 Minus public void RemoveAt(int index) {
Add comment 118 Minus lock ((lockList)) {
Add comment 119 Minus internalList.RemoveAt(index);
Add comment 120 Minus }
Add comment 121 Minus }
Add comment 117 Plus // public void RemoveAt(int index) {
Add comment 118 Plus // lock ((lockList)) {
Add comment 119 Plus // internalList.RemoveAt(index);
Add comment 120 Plus // }
Add comment 121 Plus // }
Add comment 122
Add comment 123 Minus public T this[int index]
Add comment 124 Minus {
Add comment 125 Minus get
Add comment 126 Minus {
Add comment 127 Minus lock ((lockList)) {
Add comment 128 Minus return internalList[index];
Add comment 129 Minus }
Add comment 130 Minus }
Add comment 131 Minus set
Add comment 132 Minus {
Add comment 133 Minus lock ((lockList)) {
Add comment 134 Minus internalList[index] = value;
Add comment 135 Minus }
Add comment 136 Minus }
Add comment 137 Minus }
Add comment 138 Minus }
Add comment 139 Minus }
Add comment 123 Plus // public T this[int index]
Add comment 124 Plus // {
Add comment 125 Plus // get
Add comment 126 Plus // {
Add comment 127 Plus // lock ((lockList)) {
Add comment 128 Plus // return internalList[index];
Add comment 129 Plus // }
Add comment 130 Plus // }
Add comment 131 Plus // set
Add comment 132 Plus // {
Add comment 133 Plus // lock ((lockList)) {
Add comment 134 Plus // internalList[index] = value;
Add comment 135 Plus // }
Add comment 136 Plus // }
Add comment 137 Plus // }
Add comment 138 Plus // }
Add comment 139 Plus //}
Add comment 140