key word: volatile
The
volatile keyword alerts the compiler that multiple threads will
access the
_shouldStop data member, and therefore it should not
make any optimization assumptions about the state of this member.
private volatile bool _shouldStop;
Create thread:
Worker workerObject = new Worker();
Thread workerThread = new Thread(workerObject.DoWork);
At this point, although the worker thread object exists and is configured, the actual worker thread has yet been created. This does not happen until
Main calls the Start method:
(to be continued)