1
Vote

Threading implementation issues

description

Is it possible that there is an error with the IsRunning property:
 
public bool IsRunning
    {
        get
        {
            if (worker != null)
            {
                if (worker.Join(0) == false)
                    return true;
 
                Release();
            }
            return false;
        }
    }
 
Why is Release() called here? As far as I am aware, IsRunning is only to be used to check if... the device is running :s Why try and stop the worker thread when you call it?
 
I think this leads to problems in the Stop() method:
 
public void Stop()
    {
        if (IsRunning)
        {
            stopSignal.Set();
            worker.Abort();
            if (worker != null)
            {
                worker.Join();
                Release();
            }
        }
    }
 
By calling IsRunning you effectively set _worker = null and then the code in Stop() is useless.
 
Am I missing something?

comments

KrisJ wrote Mar 23, 2009 at 1:55 PM

I think the current implementation of IsRunning can be completely be replaced by:

public bool IsRunning
    {
        get
        {
            // Check if we have a worker thread
            if (_worker == null) return false;

            return _worker.IsAlive;
         }
   }
Can the original author confirm this?

wrote Feb 14, 2013 at 7:20 PM