昨天百度到这篇文章感觉很不错(给一个我的博客的连接吧~~~http://blog.youkuaiyun.com/deandingding/article/details/39742985)今天自己在这儿玩着玩着,又玩出了一个关于这个问题的新方法,而且写起来也很简单。。。。也许很多弊端,但是目前我还不知道,如果有大牛能看出来,感激不敬!!
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
{
public delegate void Test();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Thread tr = new Thread(CrossThread);
Thread tr = new Thread(new ThreadStart(CrossThread));
tr.IsBackground = true;
tr.Start();
}
private void CrossThread()
{
Class1 c1 = new Class1(this);
Test t1=new Test(c1.Function);
while (true)
{
Thread.Sleep(1000);
this.textBox1.Invoke(t1);
}
}
}
}
Class1类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace WindowsFormsApplication1
{
class Class1
{
Form1 f1;
public Class1(Form1 f1)
{
this.f1 = f1;
}
public Class1()
{
}
public void Function()
{
f1.textBox1.Text = DateTime.Now.ToString();//这个TextBox1这个东西记得在<span style="font-family: Arial, Helvetica, sans-serif;">InitializeComponent()这个里面把它改成public</span>
}
}
}