ThreadState is stopped. No exceptions. What's happening?

in VS2008 I have a program, and it sometimes has a problem when the consumer thread stops processing. When I looked, ThreadState says "Stopped." What made the flow stop? I did not stop it. There were no exceptions. It seems really weird. thank

+3
source share
2 answers

Maybe the stream is complete?

According to this: http://msdn.microsoft.com/en-us/library/system.threading.threadstate.aspx the thread is in the Stopped state only if it stops or if it responds to the interrupt request.

+1
source

Are you sure there is no exception?

A try catch .
try catch, , , , , .

, .

.

class Worker
{
    public Exception TheadException { get; private set; }
    public void Start()
    {
        try
        {
            // Do your thing
        }
        catch (Exception ex)
        {
            TheadException = ex;
        }
    }
}

....

    static void Main(string[] args)
    {
        Worker workerObject = new Worker();
        var workerThread = new System.Threading.Thread(workerObject.Start);
        workerThread.Start();

        workerThread.Join();

        if (workerObject.TheadException != null)
            Console.WriteLine("Thread failed with exception {0}", workerObject.TheadException);
    }
+1

Source: https://habr.com/ru/post/1773628/


All Articles