Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made for v1.0.8 #13

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A simple C# repository containing a few basic useful Thread-Safe Objects.
- Collections
- ObservableDictionaryThreadSafe
- ObservableCollectionThreadSafe
- CollectionThreadSafe
- DictionaryThreadSafe
- SortedListThreadSafe
- ListThreadSafe
Expand Down Expand Up @@ -56,3 +57,14 @@ Use the `-version` option to specify an [older version](https://www.nuget.org/pa

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).

----

## Breaking changes from v1.0.7 to v1.0.8!

Observable Objects now Wait when calling `PropertyChanged` Event.
This can be overwritten durring creation or by setting Property `WaitOnNotifyPropertyChanged`. Default value is `true`.

Observable Collections now Wait when calling `CollectionChanged` Event.
This can be overwritten durring creation or by setting Property `WaitOnNotifyCollectionChanged`. Default value is `true`.

*(TIP: If you experience Dead Locks change this value to `false`.)*
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static ContactsModelList Instance
{
get
{
lock (_Locker)
lock (_InstanceLocker)
{
return _Instance ?? (_Instance= new ContactsModelList());
}
Expand All @@ -21,7 +21,7 @@ public static ContactsModelList Instance
#endregion

#region variables
protected readonly static object _Locker = new object();
protected readonly static object _InstanceLocker = new object();
private static ContactsModelList _Instance = null;
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
xmlns:b="clr-namespace:SimpleContacts.Views.Base"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:f="clr-namespace:SimpleContacts.Fonts"
Title="Contacts"
x:Class="SimpleContacts.Views.ContactsView"
x:TypeArguments="vm:ContactsViewModel"
xmlns:v="clr-namespace:SimpleContacts.Views"
xmlns:vm="clr-namespace:SimpleContacts.ViewModels"
xmlns:c="clr-namespace:SimpleContacts.Controls"
xmlns:fab="clr-namespace:ThunderDesign.Xamarin.Forms.FloatingActionButton.Controls;assembly=ThunderDesign.Xamarin.Forms.FloatingActionButton">
<ContentPage.Content>
<RefreshView Command="{Binding Source={RelativeSource AncestorType={x:Type v:ContactsView}}, Path=RefreshViewCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using ThunderDesign.Net.Threading.Interfaces;

namespace ThunderDesign.Net.Threading.Collections
{
public class CollectionThreadSafe<T> : Collection<T>, ICollectionThreadSafe<T>
{
#region constructors
public CollectionThreadSafe() : base() { }

public CollectionThreadSafe(IList<T> list) : base(list) { }
#endregion

#region properties
public bool IsSynchronized
{
get { return true; }
}

public new T this[int index]
{
get
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base[index];
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}
set
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base[index] = value;
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}
}

public new int Count
{
get
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Count;
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}
}
#endregion

#region methods
public new void Add(T item)
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.Add(item);
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new void Clear()
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.Clear();
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new bool Contains(T item)
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.Contains(item);
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new void CopyTo(T[] array, int index)
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
base.CopyTo(array, index);
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new IEnumerator<T> GetEnumerator()
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.GetEnumerator();
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new int IndexOf(T item)
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return base.IndexOf(item);
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}

public new void Insert(int index, T item)
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.Insert(index, item);
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new bool Remove(T item)
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
return base.Remove(item);
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public new void RemoveAt(int index)
{
_ReaderWriterLockSlim.EnterWriteLock();
try
{
base.RemoveAt(index);
}
finally
{
_ReaderWriterLockSlim.ExitWriteLock();
}
}

public T GetItemByIndex(int index)
{
_ReaderWriterLockSlim.EnterReadLock();
try
{
return this[index];
}
finally
{
_ReaderWriterLockSlim.ExitReadLock();
}
}
#endregion

#region variables
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ namespace ThunderDesign.Net.Threading.Collections
{
public class DictionaryThreadSafe<TKey, TValue> : Dictionary<TKey, TValue>, IDictionaryThreadSafe<TKey, TValue>
{
#region constructors
#region constructors
public DictionaryThreadSafe() : base() { }

public DictionaryThreadSafe(int capacity) : base(capacity) { }

public DictionaryThreadSafe(IEqualityComparer<TKey> comparer) : base(comparer) { }

public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary) : base(dictionary) { }

public DictionaryThreadSafe(int capacity, IEqualityComparer<TKey> comparer) : base(capacity, comparer) { }

public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) : base(dictionary, comparer) { }
#endregion
#endregion

#region properties
#region properties
public bool IsSynchronized
{
get { return true; }
Expand Down Expand Up @@ -116,10 +121,10 @@ public bool IsSynchronized
}
}
}
#endregion
#endregion

#region methods
public new virtual void Add(TKey key, TValue value)
#region methods
public new void Add(TKey key, TValue value)
{
_ReaderWriterLockSlim.EnterWriteLock();
try
Expand All @@ -132,7 +137,7 @@ public bool IsSynchronized
}
}

public new virtual void Clear()
public new void Clear()
{
_ReaderWriterLockSlim.EnterWriteLock();
try
Expand Down Expand Up @@ -212,7 +217,7 @@ public override void OnDeserialization(Object sender)
}
}
#endif
public new virtual bool Remove(TKey key)
public new bool Remove(TKey key)
{
bool result = false;
_ReaderWriterLockSlim.EnterWriteLock();
Expand All @@ -239,10 +244,10 @@ public override void OnDeserialization(Object sender)
_ReaderWriterLockSlim.ExitReadLock();
}
}
#endregion
#endregion

#region variables
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#endregion
#region variables
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ public bool IsSynchronized
_ReaderWriterLockSlim.ExitWriteLock();
}
}
#endregion
#endregion

#region variables
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#endregion
#region variables
protected readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
#endregion
}
}
Loading
Loading