I
Invalid
I launch a worker thread that periodically reads a volatile bool
abortRequested, which could be set to true by my main form.
IOW, there is one thread that can read that bool and one different
thread that can set it. See code below for an overview.
In a C or C++ environment, my current approach would be
adequate (no need to acquire exclusive access to abortRequested).
I'm guessing that I'm still OK under C# because bool is a value
type. Correct?
public abstract class ISimpleWorkerThread
{
private volatile bool abortRequested;
public ISimpleWorkerThread()
{
abortRequested = false;
}
public void Start()
{
Thread t = new Thread(new ThreadStart(DoStuff));
t.Start();
}
public abstract void DoStuff() // Polls AbortRequested
protected bool AbortRequested
{
get {return abortRequested;}
}
public void Abort()
{
abortRequested = true;
}
}
abortRequested, which could be set to true by my main form.
IOW, there is one thread that can read that bool and one different
thread that can set it. See code below for an overview.
In a C or C++ environment, my current approach would be
adequate (no need to acquire exclusive access to abortRequested).
I'm guessing that I'm still OK under C# because bool is a value
type. Correct?
public abstract class ISimpleWorkerThread
{
private volatile bool abortRequested;
public ISimpleWorkerThread()
{
abortRequested = false;
}
public void Start()
{
Thread t = new Thread(new ThreadStart(DoStuff));
t.Start();
}
public abstract void DoStuff() // Polls AbortRequested
protected bool AbortRequested
{
get {return abortRequested;}
}
public void Abort()
{
abortRequested = true;
}
}