C# 多线程实例化 定时执行 实例化线程 刷新控件

using System.Threading;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private delegate void FlushClient();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(BindThread));
            th.IsBackground = true;
            th.Start();
        }

        private void BindThread()
        {
            for (int i = 0; i < 4; i++)
            {
                Thread chlidTh = new Thread(new ThreadStart(Start));
                chlidTh.Start();
            }
        }

        public void Start()
        {
            while (true)
            {
                ThreadFunction();
                Thread.Sleep(4000);
            }
        }

        private void ThreadFunction()
        {
            if (this.dataGridView1.InvokeRequired)
            {
                FlushClient fc = new FlushClient(ThreadFunction);
                this.Invoke(fc);
            }
            else
            {
                List<Person> per = new List<Person>();
                per.Add(new Person("吴俊阳", 28));
                per.Add(new Person("吴晓阳", 20));
                this.dataGridView1.DataSource = per;
            }
        }

    }
}

 

 

 

 

 

你可能感兴趣的:(多线程)