try
t.Interrupt();
and then
t.Abort();
Or:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Boolean run = true;
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(trun));
t.Start();
}
public void trun()
{
while (run == true)
{
MessageBox.Show("dfg");
}
}
private void button1_Click(object sender, EventArgs e)
{
run = false;
}
}
}