My thread wont Stop executing.. :(

Hello there,

I recently started understanding the concept of threading and found a simple example to start a thread in JS. But it wont stop. I tried using functions like thread.Stop and thread.Abort but no use… Infact the thread keeps running even when I stop unity(Now that is strange!!). I am posting my code here…

Thanks in Advance.

var thread = System.Threading.Thread(doLogic);
function Start() {
//    thread.Start();
}

function OnGUI()
{
	if(GUI.Button(Rect (220,100,100,30),"Start Thread"))
		thread.Start();
	if(GUI.Button(Rect (100,100,100,30),"Stop Thread"))
		thread.Abort();
}

function doLogic() {
while(1)
	Debug.Log("I am unstoppable :p");
}

The best way is usually to check for a condition inside the thread, and set that condition somewhere. e.g.

var thread = System.Threading.Thread(doLogic);
function Start() {
//    thread.Start();
}
var stopThread = false;
 
function OnGUI()
{
    if(GUI.Button(Rect (220,100,100,30),"Start Thread"))
       thread.Start();
    if(GUI.Button(Rect (100,100,100,30),"Stop Thread"))
       stopThread = true;
}
 
function doLogic() {
while(!stopThread)
    Debug.Log("I am unstoppable :p");
}

I don’t use javascript so there might be a syntax error somewhere, but the concept should work.