Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread stopping

Is stopping a thread by acting the "break" command at some point a safe way to stop a thread?

like image 565
Alex Avatar asked Mar 02 '26 00:03

Alex


1 Answers

Do you mean doing something like this?

void SomeMethod()
{
    while(true)
    {
        //do something
        if(condition)
            break;
    }
}

//somewhere else...
Thread t = new Thread(SomeMethod);
t.Start();

If so, then yes, it's a safe way to end the thread.

like image 74
Phil Lamb Avatar answered Mar 04 '26 14:03

Phil Lamb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!