读书人

.NET3.5上用Lambda简化跨线程访问窗体

发布时间: 2012-12-20 09:53:21 作者: rapoo

.NET3.5下用Lambda简化跨线程访问窗体控件,避免繁复的delegate,Invoke

1,错误的代码是:

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;namespace WindowsFormsApplication5{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private string s = "http://www.chenjiliang.com/";        private void Form1_Load(object sender, EventArgs e)        {            new System.Threading.Thread(ShowTime).Start();        }        private void ShowTime()        {            this.SafeInvoke(() =>            {                textBox1.Text = DateTime.Now.ToString();            });        }    }}

?

读书人网 >编程

热点推荐