11using System ;
2+ using System . Collections . Generic ;
23using System . Threading ;
34using System . Threading . Tasks ;
45using 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}
0 commit comments