Skip to content

Commit a8e5719

Browse files
Merge pull request #8 from ShawnLaMountain/main
Added QueueThreadSafe
2 parents 6d4790f + c86485e commit a8e5719

14 files changed

+258
-11
lines changed

.github/workflows/CD.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
env:
88
TITLE: "Thread-Safe Objects"
99
DESCRIPTION: "A combination of generic Thread-Safe objects for .Net development."
10-
TAGS: "thunderdesign threading net csharp"
10+
TAGS: "thunderdesign visual%2Dstudio c%2Dsharp dotnet%2Dstandard dotnet%2Dframework dotnet%2Dcore cross%2Dplatform pcl%2Dlibrary mono xamarin%2Dforms xamarin%2Dandroid xamarin%2Dios xamarin%2Dmac xamarin%2Duwp unity csharp net dotnet threading bindable binding"
1111
#FILE_NAME: ex: "ThunderDesign.Net-PCL.Threading"
1212
FILE_NAME: "${{ github.event.repository.name }}"
1313
#REPOSITORY_NAME: ex: "ThunderDesign.Net-PCL.Threading"

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
[![CD](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml/badge.svg)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml)
44
[![Nuget](https://img.shields.io/nuget/v/ThunderDesign.Net-PCL.Threading)](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading)
55
[![License](https://img.shields.io/github/license/ThunderDesign/ThunderDesign.Net-PCL.Threading)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/LICENSE)
6+
[![Net](https://img.shields.io/badge/.net%20standard-2.0-blue)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/README.md)
67

78
A combination of generic Thread-Safe objects for .Net development.
89

910
----
1011

11-
A simple C# repository containing a few basic useful Thread-Safe Objects. Highlights include:
12+
A simple C# repository containing a few basic useful Thread-Safe Objects.
13+
### Highlights include:
1214

1315
- Collections
1416
- ObservableDictionaryThreadSafe
1517
- ObservableCollectionThreadSafe
1618
- DictionaryThreadSafe
1719
- SortedListThreadSafe
1820
- ListThreadSafe
21+
- QueueThreadSafe
1922
- DataCollections
2023
- ObservableDataDictionary
2124
- ObservableDataCollection
@@ -29,3 +32,18 @@ A simple C# repository containing a few basic useful Thread-Safe Objects. Highli
2932
- ObjectExtention
3033
- HelperClasses
3134
- ThreadHelper
35+
36+
----
37+
38+
## Installation
39+
40+
Grab the latest [ThunderDesign.Net-PCL.Threading NuGet](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading) package and install in your solution.
41+
42+
> Install-Package ThunderDesign.Net-PCL.Threading
43+
44+
Use the `-version` option to specify an [older version](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading#versions-tab) to install.
45+
46+
## Please Contribute!
47+
48+
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).
49+

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public DictionaryThreadSafe(IDictionary<TKey, TValue> dictionary, IEqualityCompa
1818
#endregion
1919

2020
#region properties
21+
public bool IsSynchronized
22+
{
23+
get { return true; }
24+
}
25+
2126
public new IEqualityComparer<TKey> Comparer
2227
{
2328
get
@@ -235,7 +240,6 @@ public override void OnDeserialization(Object sender)
235240

236241
#region variables
237242
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
238-
239243
#endregion
240244
}
241245
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Threading;
5+
using ThunderDesign.Net_PCL.Threading.Interfaces;
56

67
namespace ThunderDesign.Net_PCL.Threading.Collections
78
{
8-
public class ListThreadSafe<T> : List<T>
9+
public class ListThreadSafe<T> : List<T>, IListThreadSafe<T>
910
{
1011
#region constructors
1112
public ListThreadSafe() : base() { }
@@ -16,6 +17,11 @@ public ListThreadSafe(int capacity) : base(capacity) { }
1617
#endregion
1718

1819
#region properties
20+
public bool IsSynchronized
21+
{
22+
get { return true; }
23+
}
24+
1925
public new T this[int index]
2026
{
2127
get

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public ObservableCollectionThreadSafe(List<T> list) : base(list) { }
2222
#endregion
2323

2424
#region properties
25+
public bool IsSynchronized
26+
{
27+
get { return true; }
28+
}
29+
2530
public new T this[int index]
2631
{
2732
get
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using ThunderDesign.Net_PCL.Threading.Interfaces;
4+
5+
namespace ThunderDesign.Net.Threading.Collections
6+
{
7+
public class QueueThreadSafe<T> : Queue<T>, IQueueThreadSafe<T>
8+
{
9+
#region constructors
10+
public QueueThreadSafe() : base() { }
11+
public QueueThreadSafe(IEnumerable<T> collection) : base(collection) { }
12+
public QueueThreadSafe(int capacity) : base(capacity) { }
13+
#endregion
14+
15+
#region properties
16+
public bool IsSynchronized
17+
{
18+
get { return true; }
19+
}
20+
21+
public new int Count
22+
{
23+
get
24+
{
25+
_ReaderWriterLockSlim.EnterReadLock();
26+
try
27+
{
28+
return base.Count;
29+
}
30+
finally
31+
{
32+
_ReaderWriterLockSlim.ExitReadLock();
33+
}
34+
}
35+
}
36+
#endregion
37+
38+
#region methods
39+
public new void Clear()
40+
{
41+
_ReaderWriterLockSlim.EnterWriteLock();
42+
try
43+
{
44+
base.Clear();
45+
}
46+
finally
47+
{
48+
_ReaderWriterLockSlim.ExitWriteLock();
49+
}
50+
}
51+
52+
public new bool Contains(T item)
53+
{
54+
_ReaderWriterLockSlim.EnterReadLock();
55+
try
56+
{
57+
return base.Contains(item);
58+
}
59+
finally
60+
{
61+
_ReaderWriterLockSlim.ExitReadLock();
62+
}
63+
}
64+
65+
public new void CopyTo(T[] array, int arrayIndex)
66+
{
67+
_ReaderWriterLockSlim.EnterReadLock();
68+
try
69+
{
70+
base.CopyTo(array, arrayIndex);
71+
}
72+
finally
73+
{
74+
_ReaderWriterLockSlim.ExitReadLock();
75+
}
76+
}
77+
78+
public new T Dequeue()
79+
{
80+
_ReaderWriterLockSlim.EnterWriteLock();
81+
try
82+
{
83+
return base.Dequeue();
84+
}
85+
finally
86+
{
87+
_ReaderWriterLockSlim.ExitWriteLock();
88+
}
89+
}
90+
91+
public new void Enqueue(T item)
92+
{
93+
_ReaderWriterLockSlim.EnterWriteLock();
94+
try
95+
{
96+
base.Enqueue(item);
97+
}
98+
finally
99+
{
100+
_ReaderWriterLockSlim.ExitWriteLock();
101+
}
102+
}
103+
104+
public new Enumerator GetEnumerator()
105+
{
106+
_ReaderWriterLockSlim.EnterReadLock();
107+
try
108+
{
109+
return base.GetEnumerator();
110+
}
111+
finally
112+
{
113+
_ReaderWriterLockSlim.ExitReadLock();
114+
}
115+
}
116+
117+
public new T Peek()
118+
{
119+
_ReaderWriterLockSlim.EnterReadLock();
120+
try
121+
{
122+
return base.Peek();
123+
}
124+
finally
125+
{
126+
_ReaderWriterLockSlim.ExitReadLock();
127+
}
128+
}
129+
130+
public new T[] ToArray()
131+
{
132+
_ReaderWriterLockSlim.EnterReadLock();
133+
try
134+
{
135+
return base.ToArray();
136+
}
137+
finally
138+
{
139+
_ReaderWriterLockSlim.ExitReadLock();
140+
}
141+
}
142+
143+
public new void TrimExcess()
144+
{
145+
_ReaderWriterLockSlim.EnterWriteLock();
146+
try
147+
{
148+
base.TrimExcess();
149+
}
150+
finally
151+
{
152+
_ReaderWriterLockSlim.ExitWriteLock();
153+
}
154+
}
155+
#endregion
156+
157+
#region variables
158+
protected static readonly ReaderWriterLockSlim _ReaderWriterLockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
159+
#endregion
160+
}
161+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System.Collections.Generic;
22
using System.Threading;
3+
using ThunderDesign.Net_PCL.Threading.Interfaces;
34

45
namespace ThunderDesign.Net_PCL.Threading.Collections
56
{
6-
public class SortedListThreadSafe<TKey, TValue> : SortedList<TKey, TValue>
7+
public class SortedListThreadSafe<TKey, TValue> : SortedList<TKey, TValue>, ISortedListThreadSafe<TKey, TValue>
78
{
89
#region constructors
910
public SortedListThreadSafe() : base() { }
@@ -16,10 +17,15 @@ public SortedListThreadSafe(IDictionary<TKey, TValue> dictionary, IComparer<TKey
1617

1718
public SortedListThreadSafe(int capacity) : base(capacity) { }
1819

19-
public SortedListThreadSafe(int capacity, IComparer<TKey> comparer) : base(comparer) { }
20+
public SortedListThreadSafe(int capacity, IComparer<TKey> comparer) : base(capacity, comparer) { }
2021
#endregion
2122

2223
#region properties
24+
public bool IsSynchronized
25+
{
26+
get { return true; }
27+
}
28+
2329
public new int Capacity
2430
{
2531
get
@@ -147,6 +153,7 @@ public SortedListThreadSafe(int capacity, IComparer<TKey> comparer) : base(compa
147153
_ReaderWriterLockSlim.EnterWriteLock();
148154
try
149155
{
156+
Queue<string> ts = new Queue<string>();
150157
base.Add(key, value);
151158
}
152159
finally

src/ThunderDesign.Net-PCL.Threading/DataCollections/ObservableDataDictionary.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public ObservableDataDictionary(IDictionary<TKey, TValue> dictionary, IEqualityC
2424
//Hiding base.Add(TKey key, TValue value);
2525
}
2626

27+
void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
28+
{
29+
this.Add(value);
30+
}
31+
2732
public virtual void Add(TValue value)
2833
{
2934
base.Add(value.Id, value);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using System.Runtime.Serialization;
34

45
namespace ThunderDesign.Net.Threading.Interfaces
56
{
6-
public interface IDictionaryThreadSafe : IDictionary
7+
public interface IDictionaryThreadSafe : IDictionary, IDeserializationCallback, ISerializable
78
{
89
}
910

10-
public interface IDictionaryThreadSafe<TKey, TValue> : IDictionary<TKey, TValue>, IDictionaryThreadSafe
11+
public interface IDictionaryThreadSafe<TKey, TValue> : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>, IDictionaryThreadSafe
1112
{
1213
}
1314
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
namespace ThunderDesign.Net_PCL.Threading.Interfaces
5+
{
6+
public interface IListThreadSafe : IList
7+
{
8+
}
9+
10+
public interface IListThreadSafe<T> : IList<T>, IReadOnlyList<T>, IListThreadSafe
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)