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
    {
        int i = 0;
        Thread t;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            t = new Thread(new ThreadStart(test));
            i = 0;
            t.Start();
        }
        public void test()
        {
            while (i < 1000000)
            {
                i++;             
                textBox1.Text = i.ToString();
            }
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (t!=null && t.ThreadState==ThreadState.Running)  t.Abort();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (t.ThreadState == ThreadState.Suspended) t.Resume(); else   t.Suspend();
            
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (t.ThreadState==ThreadState.Running)  t.Abort();
        }

    }
}
