wm使用多线程的问题,PC上用则没问题,看了不少资料还是不懂
设计视图和错误提示如图
代码如下
using System;using System.Windows.Forms; using System.Threading;namespace SmartDeviceProject1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f1 = new Form2("1"); Thread th = new Thread(new ThreadStart(f1.DelayShow)); th.Start(); Form2 f2 = new Form2("2"); f2.ShowDialog(); } }}
using System;using System.Windows.Forms;using System.Threading;namespace SmartDeviceProject1{ public partial class Form2 : Form { public Form2(string s) { InitializeComponent(); this.Text = s; } private void button1_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Yes; } private void button2_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.No; } public void DelayShow() { Thread.Sleep(5000); this.ShowDialog(); } }}