'Why does this loop in another thread fail to terminate?

I am using .NET Framework version 4.7.2.

I created a bool variable called threadState. This variable tells the thread, draw, to exit, but even if you make the variable false the thread does not terminate. Variables and labels in functions put in a thread are not used by any thread other than this one.

Thread code:

private void drawReadPoint()
{
    while (threadState)
    {
        RxReadLabel.Invoke((MethodInvoker)delegate ()
        {
            RxReadLabel.Text = "▼" + _rx.queue.readIdx.ToString();
            readPoint.X = Convert.ToInt32(map(_rx.queue.readIdx, 0, _rx.maxSize, 0, 1100) + 28);
            readPoint.Y = 1;
            RxReadLabel.Location = readPoint;
        }
        );
        RxWriteLabel.Invoke((MethodInvoker)delegate ()
        {
            RxWriteLabel.Text = "△" + _rx.queue.readIdx.ToString();
            writePoint.X = Convert.ToInt32(map(_rx.queue.writeIdx, 0, _rx.maxSize, 0, 1100) + 28);
            writePoint.Y = 29;
            RxWriteLabel.Location = writePoint;
        }
        );
        richTextBox_log.Invoke((MethodInvoker)delegate () { richTextBox_log.AppendText("중"); });
        Thread.Sleep(1);
    }
    richTextBox_log.Invoke((MethodInvoker)delegate () { richTextBox_log.AppendText("끝!!"); });
}

Closing code:

private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
    threadState = false;
    richTextBox_log.Invoke((MethodInvoker)delegate () { richTextBox_log.AppendText("시작"); });
    draw.Join();
    richTextBox_log.Invoke((MethodInvoker)delegate () { richTextBox_log.AppendText("진짜 끝"); });
    readqThread.Abort();
    e.Cancel = true;
    this.Invoke(new EventHandler(delegate
    {
        Thread.Sleep(10);
        Dispose();
        e.Cancel = false;
    }));
    Application.Exit();
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source