C#winform控件多线程访问

来源:互联网 发布:计算复杂性 正规算法 编辑:程序博客网 时间:2024/06/05 07:22
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 多线程访问{    public partial class Form1 : Form    {        private delegate void client();        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {            Thread threadnew = new Thread(threadflush);            threadnew.IsBackground = true;            threadnew.Start();        }        private void threadflush()        {            while (true)            {                Thread.Sleep(1000);                threadfunction();            }        }        private void threadfunction()        {            if (textBox1.InvokeRequired)            {                client fc = new client(threadfunction);                this.Invoke(fc);            }            else            {                textBox1.AppendText("1");            }        }    }}
原文地址:http://hi.baidu.com/gwj6396668/item/773ce30f181375d01ef04661
0 0