Skip to content

Commit 04eb2ba

Browse files
committed
State and processorThreadStarting moved to Work method.
1 parent 3f42a91 commit 04eb2ba

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

Shuttle.Core.Threading/.package/package.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package>
44
<metadata>
55
<id>Shuttle.Core.Threading</id>
6-
<version>13.0.0</version>
6+
<version>13.1.0</version>
77
<authors>Eben Roux</authors>
88
<owners>Eben Roux</owners>
99
<license type="expression">BSD-3-Clause</license>

Shuttle.Core.Threading/ProcessorThread.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using Shuttle.Core.Contract;
@@ -16,6 +17,8 @@ public class ProcessorThread
1617
private bool _sync;
1718
private Thread _thread;
1819

20+
private readonly Dictionary<string, object> _state = new Dictionary<string, object>();
21+
1922
public ProcessorThread(string name, IProcessor processor, ProcessorThreadOptions processorThreadOptions)
2023
{
2124
Name = Guard.AgainstNull(name, nameof(name));
@@ -65,8 +68,6 @@ public void Start(bool sync)
6568

6669
_eventArgs = new ProcessorThreadEventArgs(Name, _thread.ManagedThreadId);
6770

68-
ProcessorThreadStarting?.Invoke(this, _eventArgs);
69-
7071
_thread.Start();
7172

7273
while (!_thread.IsAlive && !CancellationToken.IsCancellationRequested)
@@ -126,6 +127,8 @@ public void Stop()
126127

127128
private async void Work()
128129
{
130+
ProcessorThreadStarting?.Invoke(this, _eventArgs);
131+
129132
while (!CancellationToken.IsCancellationRequested)
130133
{
131134
ProcessorExecuting?.Invoke(this, _eventArgs);
@@ -151,5 +154,19 @@ private async void Work()
151154
}
152155
}
153156
}
157+
158+
public void SetState(string key, object value)
159+
{
160+
Guard.AgainstNullOrEmptyString(key, nameof(key));
161+
162+
_state[key] = value;
163+
}
164+
165+
public object GetState(string key)
166+
{
167+
Guard.AgainstNullOrEmptyString(key, nameof(key));
168+
169+
return _state.ContainsKey(key) ? _state[key] : null;
170+
}
154171
}
155172
}

Shuttle.Core.Threading/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
[assembly: AssemblyTitle(".NET Standard")]
1414
#endif
1515

16-
[assembly: AssemblyVersion("13.0.0.0")]
16+
[assembly: AssemblyVersion("13.1.0.0")]
1717
[assembly: AssemblyCopyright("Copyright (c) 2024, Eben Roux")]
1818
[assembly: AssemblyProduct("Shuttle.Core.Threading")]
1919
[assembly: AssemblyCompany("Eben Roux")]
2020
[assembly: AssemblyConfiguration("Release")]
21-
[assembly: AssemblyInformationalVersion("13.0.0")]
21+
[assembly: AssemblyInformationalVersion("13.1.0")]
2222
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)