c# winform 多线程高手进

代码段1:打开后直接闪了一下就没了!!为什么  public partial class Form1 : Form    {        public Form2()        {            InitializeComponent();        }        private Thread tr;        private void button1_Click(object sender, EventArgs e)        {            tr = new Thread(new ThreadStart(Do));            tr.IsBackground = false;            tr.Start();        }        private void Do()        {            Form3 f = new Form3();            f.Show();        }    }     代码段2:只能打开一个save ???请问是怎么回事?? public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            Form2 f = new Form2();            f.Show();            Form2 f1 = new Form2();            f1.Show();        }    }   public partial class Form2 : Form    {        public Form2()        {            InitializeComponent();            this.FormClosing += new FormClosingEventHandler(Form2_FormClosing);            Thread td = new Thread(DO);            td.Name = "from2";            td.Start();        }        private void DO()        {            Thread.Sleep(2000);            this.Invoke(new Action(() =>            {                this.Close();            }));        }        void Form2_FormClosing(object sender, FormClosingEventArgs e)        {            System.Windows.Forms.SaveFileDialog sd = new SaveFileDialog();            sd.ShowDialog();        }    }
阿晨1998
浏览 537回答 3
3回答

隔江千里

试了下第一种,弹出两个,关掉一个不会一起关掉另一个啊…… 第二种应该是一个保存框关掉才会出现第二个吧

青春有我

第一个问题不提。 第二个模态对话框在多线程中要指定对话框的所有者,你的代码中会同时关闭两个对话框,改成:sd.ShowDialog(this); 试试
打开App,查看更多内容
随时随地看视频慕课网APP