ThreadStart Wrappers vs. State
-
I have a class that performs a single atomic, stateless task. However, I need to multithread this class in a barrage against a test server, and the ThreadStart delegate constructor must have a parameterless method. I have two alternatives: to add state to my original class and set this state through properties before starting the thread, or isolating the state in a wrapper class whose parameterless method calls the parameterful method in the original class? What say ye? The DJ's took pills to stay awake and play for seven days. - Jim Morrison, Black Polished Chrome.
-
I have a class that performs a single atomic, stateless task. However, I need to multithread this class in a barrage against a test server, and the ThreadStart delegate constructor must have a parameterless method. I have two alternatives: to add state to my original class and set this state through properties before starting the thread, or isolating the state in a wrapper class whose parameterless method calls the parameterful method in the original class? What say ye? The DJ's took pills to stay awake and play for seven days. - Jim Morrison, Black Polished Chrome.
I'd go with the latter. It avoids synchronization issues which can happen when properties are being set and multiple threads are started. Regards Senthil _____________________________ My Blog | My Articles | WinMacro