Skip to content

Commit 208d034

Browse files
Merge pull request #13 from ShawnLaMountain/main
Changes made for v1.0.8
2 parents 694713a + 2bbcfc4 commit 208d034

21 files changed

+506
-214
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A simple C# repository containing a few basic useful Thread-Safe Objects.
1515
- Collections
1616
- ObservableDictionaryThreadSafe
1717
- ObservableCollectionThreadSafe
18+
- CollectionThreadSafe
1819
- DictionaryThreadSafe
1920
- SortedListThreadSafe
2021
- ListThreadSafe
@@ -56,3 +57,14 @@ Use the `-version` option to specify an [older version](https://www.nuget.org/pa
5657

5758
This is an open source project that welcomes contributions/suggestions/bug reports from those who use it. If you have any ideas on how to improve the library, please [post an issue here on GitHub](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/issues). Please check out the [How to Contribute](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/.github/CONTRIBUTING.md).
5859

60+
----
61+
62+
## Breaking changes from v1.0.7 to v1.0.8!
63+
64+
Observable Objects now Wait when calling `PropertyChanged` Event.
65+
This can be overwritten durring creation or by setting Property `WaitOnNotifyPropertyChanged`. Default value is `true`.
66+
67+
Observable Collections now Wait when calling `CollectionChanged` Event.
68+
This can be overwritten durring creation or by setting Property `WaitOnNotifyCollectionChanged`. Default value is `true`.
69+
70+
*(TIP: If you experience Dead Locks change this value to `false`.)*

samples/Xamarin/SimpleContacts/SimpleContacts/Models/ContactsModelList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static ContactsModelList Instance
1212
{
1313
get
1414
{
15-
lock (_Locker)
15+
lock (_InstanceLocker)
1616
{
1717
return _Instance ?? (_Instance= new ContactsModelList());
1818
}
@@ -21,7 +21,7 @@ public static ContactsModelList Instance
2121
#endregion
2222

2323
#region variables
24-
protected readonly static object _Locker = new object();
24+
protected readonly static object _InstanceLocker = new object();
2525
private static ContactsModelList _Instance = null;
2626
#endregion
2727
}

samples/Xamarin/SimpleContacts/SimpleContacts/Views/ContactsView.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
xmlns:b="clr-namespace:SimpleContacts.Views.Base"
44
xmlns="http://xamarin.com/schemas/2014/forms"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6-
xmlns:f="clr-namespace:SimpleContacts.Fonts"
76
Title="Contacts"
87
x:Class="SimpleContacts.Views.ContactsView"
98
x:TypeArguments="vm:ContactsViewModel"
109
xmlns:v="clr-namespace:SimpleContacts.Views"
1110
xmlns:vm="clr-namespace:SimpleContacts.ViewModels"
12-
xmlns:c="clr-namespace:SimpleContacts.Controls"
1311
xmlns:fab="clr-namespace:ThunderDesign.Xamarin.Forms.FloatingActionButton.Controls;assembly=ThunderDesign.Xamarin.Forms.FloatingActionButton">
1412
<ContentPage.Content>
1513
<RefreshView Command="{Binding Source={RelativeSource AncestorType={x:Type v:ContactsView}}, Path=RefreshViewCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}">
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using System.Threading;
4+
using ThunderDesign.Net.Threading.Interfaces;
5+
6+
namespace ThunderDesign.Net.Threading.Collections
7+
{
8+
public class CollectionThreadSafe<T> : Collection<T>, ICollectionThreadSafe<T>
9+
{
10+
#region constructors
11+
public CollectionThreadSafe() : base() { }
12+
13+
public CollectionThreadSafe(IList<T> list) : base(list) { }
14+
#endregion
15+
16+
#region properties
17+
public bool IsSynchronized
18+
{
19+
get { return true; }
20+
}
21+
22+
public new T this[int index]
23+
{
24+
get
25+
{
26+
_ReaderWriterLockSlim.EnterReadLock();
27+
try
28+
{
29+
return base[index];
30+
}
31+
finally
32+
{
33+
_ReaderWriterLockSlim.ExitReadLock();
34+
}
35+
}
36+
set
37+
{
38+
_ReaderWriterLockSlim.EnterWriteLock();
39+
try
40+
{
41+
base[index] = value;
42+
}
43+
finally
44+
{
45+
_ReaderWriterLockSlim.ExitWriteLock();
46+
}
47+
}
48+
}
49+
50+
public new int Count
51+
{
52+
get
53+
{
54+
_ReaderWriterLockSlim.EnterReadLock();
55+
try
56+
{
57+
return base.Count;
58+
}
59+
finally
60+
{
61+
_ReaderWriterLockSlim.ExitReadLock();
62+
}
63+
}
64+
}
65+
#endregion
66+
67+
#region methods
68+
public new void Add(T item)
69+
{
70+
_ReaderWriterLockSlim.EnterWriteLock();
71+
try
72+
{
73+
base.Add(item);
74+
}
75+
finally
76+
{
77+
_ReaderWriterLockSlim.ExitWriteLock();
78+
}
79+
}
80+
81+
public new void Clear()
82+
{
83+
_ReaderWriterLockSlim.EnterWriteLock();
84+
try
85+
{
86+
base.Clear();
87+
}
88+
finally
89+
{
90+
_ReaderWriterLockSlim.ExitWriteLock();
91+
}
92+
}
93+
94+
public new bool Contains(T item)
95+
{
96+
_ReaderWriterLockSlim.EnterReadLock();
97+
try
98+
{
99+
return base.Contains(item);
100+
}
101+
finally
102+
{
103+
_ReaderWriterLockSlim.ExitReadLock();
104+
}
105+
}
106+
107+
public new void CopyTo(T[] array, int index)
108+
{
109+
_ReaderWriterLockSlim.EnterReadLock();
110+
try
111+
{
112+
base.CopyTo(array, index);
113+
}
114+
finally
115+
{
116+
_ReaderWriterLockSlim.ExitReadLock();
117+
}
118+
}
119+
120+
public new IEnumerator<T> GetEnumerator()
121+
{
122+
_ReaderWriterLockSlim.EnterReadLock();
123+
try
124+
{
125+
return base.GetEnumerator();
126+
}
127+
finally
128+
{
129+
_ReaderWriterLockSlim.ExitReadLock();
130+
}
131+
}
132+
133+
public new int IndexOf(T item)
134+
{
135+
_ReaderWriterLockSlim.EnterReadLock();
136+
try
137+
{
138+
return base.IndexOf(item);
139+
}
140+
finally
141+
{
142+
_ReaderWriterLockSlim.ExitReadLock();
143+
}
144+
}
145+
146+
public new void Insert(int index, T item)
147+
{
148+
_ReaderWriterLockSlim.EnterWriteLock();
149+
try
150+
{
151+
base.Insert(index, item);
152+
}
153+
finally
154+
{
155+
_ReaderWriterLockSlim.ExitWriteLock();
156+
}
157+
}
158+
159+
public new bool Remove(T item)
160+
{
161+
_ReaderWriterLockSlim.EnterWriteLock();
162+
try
163+
{
164+
return base.Remove(item);
165+
}
166+
finally
167+
{
168+
_ReaderWriterLockSlim.ExitWriteLock();
169+
}
170+
}
171+
172+
public new void RemoveAt(int index)
173+
{
174+
_ReaderWriterLockSlim.EnterWriteLock();
175+
try
176+
{
177+
base.RemoveAt(index);
178+
}
179+
finally
180+
{
181+
_ReaderWriterLockSlim.ExitWriteLock();
182+
}
183+
}
184+
185+
public T GetItemByIndex(int index)
186+
{
187+
_ReaderWriterLockSlim.EnterReadLock();
188+
try
189+
{
190+
return this[index];
191+
}
192+
finally
193+
{
194+
_ReaderWriterLockSlim.ExitReadLock();
195+
}
196+
}
197+
#endregion
198+
199+
#region variables
200+
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
201+
#endregion
202+
}
203+
}

src/ThunderDesign.Net-PCL.Threading/Collections/DictionaryThreadSafe.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ namespace ThunderDesign.Net.Threading.Collections
1010
{
1111
public class DictionaryThreadSafe<TKey, TValue> : Dictionary<TKey, TValue>, IDictionaryThreadSafe<TKey, TValue>
1212
{
13-
#region constructors
13+
#region constructors
1414
public DictionaryThreadSafe() : base() { }
15+
1516
public DictionaryThreadSafe(int capacity) : base(capacity) { }
17+
1618
public DictionaryThreadSafe(IEqualityComparer<TKey> comparer) : base(comparer) { }
19+
1720
public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary) : base(dictionary) { }
21+
1822
public DictionaryThreadSafe(int capacity, IEqualityComparer<TKey> comparer) : base(capacity, comparer) { }
23+
1924
public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) : base(dictionary, comparer) { }
20-
#endregion
25+
#endregion
2126

22-
#region properties
27+
#region properties
2328
public bool IsSynchronized
2429
{
2530
get { return true; }
@@ -116,10 +121,10 @@ public bool IsSynchronized
116121
}
117122
}
118123
}
119-
#endregion
124+
#endregion
120125

121-
#region methods
122-
public new virtual void Add(TKey key, TValue value)
126+
#region methods
127+
public new void Add(TKey key, TValue value)
123128
{
124129
_ReaderWriterLockSlim.EnterWriteLock();
125130
try
@@ -132,7 +137,7 @@ public bool IsSynchronized
132137
}
133138
}
134139

135-
public new virtual void Clear()
140+
public new void Clear()
136141
{
137142
_ReaderWriterLockSlim.EnterWriteLock();
138143
try
@@ -212,7 +217,7 @@ public override void OnDeserialization(Object sender)
212217
}
213218
}
214219
#endif
215-
public new virtual bool Remove(TKey key)
220+
public new bool Remove(TKey key)
216221
{
217222
bool result = false;
218223
_ReaderWriterLockSlim.EnterWriteLock();
@@ -239,10 +244,10 @@ public override void OnDeserialization(Object sender)
239244
_ReaderWriterLockSlim.ExitReadLock();
240245
}
241246
}
242-
#endregion
247+
#endregion
243248

244-
#region variables
245-
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
246-
#endregion
249+
#region variables
250+
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
251+
#endregion
247252
}
248253
}

src/ThunderDesign.Net-PCL.Threading/Collections/ListThreadSafe.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,10 @@ public bool IsSynchronized
699699
_ReaderWriterLockSlim.ExitWriteLock();
700700
}
701701
}
702-
#endregion
702+
#endregion
703703

704-
#region variables
705-
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
706-
#endregion
704+
#region variables
705+
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
706+
#endregion
707707
}
708708
}

0 commit comments

Comments
 (0)