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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void MyMethod(); //声明一个委托,以使其它线程访问 //按钮
private void button1_Click(object sender, EventArgs e)
{
Thread aaa = new Thread(new ThreadStart(OpenDialogOnOtherThread));
aaa.Start();
}
//其它线程打开对话框
void OpenDialogOnOtherThread()
{
MyMethod OpenDialog = new MyMethod(this.OpenDialog);
this.Invoke(OpenDialog); //在当前线程,调用OpenDialog
}
//打开对话框
void OpenDialog()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
}
}
}