private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(TripleKill));
th.Start();
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "5");
MessageBox.Show("hello world");
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "hello world");
}
private void TripleKill()
{
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "TripleKill-1");
//MessageBox.Show("hello456");
this.Invoke(new DelegateTest(changeText1));
this.BeginInvoke(new DelegateTest(changeBtnText));
this.BeginInvoke(new DelegateTest(DoubleKill)).ToString();
}
private void changeText1()
{
//MessageBox.Show("BeginInvoke-changeText1");
textBox1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "789";
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "changeText1.2");
}
private void changeBtnText()
{
Thread.Sleep(4000);
this.button1.Text = "click me";
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "changeBtnText-click me-3");
MessageBox.Show("click me");
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "changeBtnText-click me-31");
Thread.Sleep(2000);
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "changeBtnText-click me-32");
}
private void DoubleKill()
{
Thread.Sleep(3000);
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "TripleKill-Invoke-4");
MessageBox.Show("Invoke");
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--" + "TripleKill-Invoke-41");
}
结果:
2024-08-28 14:07:19.502--5
2024-08-28 14:07:19.553--changeText1.2
2024-08-28 14:07:23.560--changeBtnText-click me-3
2024-08-28 14:07:26.579--TripleKill-Invoke-4
2024-08-28 14:07:27.976--TripleKill-Invoke-41
2024-08-28 14:07:28.952--changeBtnText-click me-31
2024-08-28 14:07:30.952--changeBtnText-click me-32
2024-08-28 14:07:57.866--hello world