Showing posts with label thread. Show all posts
Showing posts with label thread. Show all posts

Sunday, July 19, 2009

Create a new thread


Thread trd;
private void btnRun_Click(object sender, EventArgs e)
{
trd = new Thread(new ThreadStart(this.ThreadTask));
trd.IsBackground = true;
trd.Start();
}

[STAThread]
private void ThreadTask()
{
//Do something here
}

private void btnStop_Click(object sender, EventArgs e)
{
if (trd != null)
{
trd.Abort();
trd = null;
}
}
private void btmExit_Click(object sender, EventArgs e)
{
Application.Exit();
}