JFrame zawiesza się podczas ciągłego uruchamiania kodu

Mam problem podczas pracyJFrame, który się zawiesza podczas ciągłego uruchamiania kodu. Poniżej znajduje się mój kod:

Po kliknięciubtnRun, Zadzwoniłem do funkcjiMainLoop():

ActionListener btnRun_Click = new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        MainLoop();
    }
};

WdrożenieMainLoop():

void MainLoop()
{
    Hopper = new CHopper(this);
    System.out.println(Hopper);
    btnRun.setEnabled(false);
    textBox1.setText("");
    Hopper.getM_cmd().ComPort = helpers.Global.ComPort;
    Hopper.getM_cmd().SSPAddress = helpers.Global.SSPAddress;
    Hopper.getM_cmd().Timeout = 2000;
    Hopper.getM_cmd().RetryLevel = 3;


    System.out.println("In MainLoop: " + Hopper);

    // First connect to the validator
    if (ConnectToValidator(10, 3))
    {
        btnHalt.setEnabled(true);
        Running = true;

        textBox1.append("\r\nPoll Loop\r\n"
                + "*********************************\r\n");
    }

    // This loop won't run until the validator is connected
    while (Running)
    {
        // poll the validator
        if (!Hopper.DoPoll(textBox1))
        {
            // If the poll fails, try to reconnect
            textBox1.append("Attempting to reconnect...\r\n");
            if (!ConnectToValidator(10, 3))
            {
                // If it fails after 5 attempts, exit the loop
                Running = false;
            }
        }
        // tick the timer
                // timer1.start();
        // update form
        UpdateUI();
        // setup dynamic elements of win form once
        if (!bFormSetup)
        {
            SetupFormLayout();
            bFormSetup = true;
        }

    }

    //close com port
    Hopper.getM_eSSP().CloseComPort();

    btnRun.setEnabled(true);
    btnHalt.setEnabled(false);
}

wMainLoop() funkcja, pętla while działa nieprzerwanie, dopóki nie działa prawdziwy błąd, jeśli chcę zatrzymać tę pętlę podczas gdy muszę ustawić Uruchom na fałszywe, co jest wykonywane na innym przyciskubtnHalt:

ActionListener btnHalt_Click = new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        textBox1.append("Poll loop stopped\r\n");
        System.out.println("Hoper Stopped");
        Running = false;
    }
};

alebtnHalt nie odpowiada, cała ramka jest zamrożona, również nie pokazuje żadnego logowaniatextarea.

questionAnswers(1)

yourAnswerToTheQuestion