日期:2014-05-17 浏览次数:20869 次
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 ASY
{
public partial class Form1 : Form
{
public delegate void delegateInvoke();
public Form1()
{
InitializeComponent();
int threadid = AppDomain.GetCurrentThreadId();
MessageBox.Show("Main thread is "+ threadid.ToString());
}
public void InvokedMethod()
{
int threadid = AppDomain.GetCurrentThreadId();
//与窗体是同一个线程
MessageBox.Show("Sub thread is " + threadid.ToString());
textBox1.Text = "New thread";
}
private void button1_Click(object sender, EventArgs e)
{
delegateInvoke delegateinvoke = new delegateInvoke(InvokedMethod);
IAsyncResult ir = textBox1.BeginInvoke(delegateinvoke);
}
}
}