线程中的保存文件对话框弹不出,必须在sfd.ShowDialog()加入参数this,为什么?
代码:窗体上一个button。
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(TestSave);
th.IsBackground = true;
th.Start();
}
private void TestSave()
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog(this) == DialogResult.OK)
{
MessageBox.Show(sfd.FileName);
}
}
代码:窗体上一个button。
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(TestSave);
th.IsBackground = true;
th.Start();
}
private void TestSave()
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog(this) == DialogResult.OK)
{
MessageBox.Show(sfd.FileName);
}
}