See I did a solution in asp.net
Code are following below
Thread thLoop = null;
static string value = "";
static bool isStopRequired = false;
protected void Button1_Click(object sender, EventArgs e)
{
isStopRequired = false;
value = "";
thLoop = new Thread(new ThreadStart(GetLoop));
thLoop.Start();
}
void GetLoop()
{
for (int i = 0; i <= 50000; i++)
{
value += " " + i.ToString();
if (isStopRequired) break;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
isStopRequired = true;
if (thLoop != null) thLoop.Abort();
Response.Write(value);
}