遇到问题:
调用文件选择窗口必须是单线程,需要进行设置:choosefileth.SetApartmentState(ApartmentState.STA);
在调用时显示不是父窗口调用:Control.CheckForIllegalCrossThreadCalls = false;
调用完成后需要关闭线程并初始化,以便下一次调用:
Application.ExitThread();
choosefileth = new Thread(new ThreadStart(choosefile));
choosefileth.SetApartmentState(ApartmentState.STA);
定义文件夹选择窗口:
public Thread choosefileth;
public virtual void choosefile(){
OpenFileDialog textdlg = new OpenFileDialog();
if (textdlg.ShowDialog() == DialogResult.OK)
{
choosefilename = textdlg.FileName;
this.textBox3.Text = Path.GetFileNameWithoutExtension(textdlg.FileName);
this.textBox3.ReadOnly = true;