weird bugs.
I've been reading over Jon Skeet's GREAT website about threading and have
tried to apply some of what I learned. There is almost too much information
there for me, I had a hard time deciding what method or design to choose.
I hoped that I could post this skeleton class for a quick review to make
sure I'm on the right track. If you have a minute, I would appreciate your
comments.
Expand|Select|Wrap|Line Numbers
- public class CalibrateDAQViewPresenter :
- FunctionalTestModulePresenter<ICalibrateDAQView>
- {
- private bool _stopping = false;
- private bool _stopped = false;
- private static readonly object _lockObject = new object();
- protected override void Dispose(bool disposing)
- {
- // let the polling thread exit
- lock (_lockObject)
- {
- _stopping = false;
- while (_stopped == false) ;
- }
- base.Dispose(disposing);
- }
- public void OnViewReady()
- {
- _startReadingData();
- }
- private void _startReadingData()
- {
- _stopped = false;
- _stopping = false;
- ThreadPool.QueueUserWorkItem(
- delegate
- {
- _dataPoller();
- }
- );
- }
- private void _dataPoller()
- {
- while(true)
- {
- lock(_lockObject)
- {
- if(_stopping)
- {
- _stopped = true;
- return;
- }
- // do stuff and update view
- }
- Thread.Sleep(100);
- }
- }
- }
Thanks for reading!