使用多线程有几个需要注意的地方:
1.程序入口前的属性标签[STAThread]改为[MTAThread]
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[MTAThread]
static void Main(){...}
2.改为[MTAThread]后,主线程中弹出弹窗会出错,例如OpenFileDialog,此时应开辟子线程来弹出,设置线程属性
SetApartmentState(ApartmentState.STA)
private void tbMXD_MouseDown(object sender, MouseEventArgs e)
{
Thread invokeThread = new Thread(new ThreadStart(InvokeMethod1));
invokeThread.SetApartmentState(ApartmentState.STA);
invokeThread.Start();
//OpenFileDialog dialog = new OpenFileDialog();
//dialog.FileName = tbMXD.Text;
//dialog.Filter = "(*.mxd)|*.mxd";
//if (dialog.ShowDialog() == DialogResult.OK)
//{
//