using System;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(YourThread);
th.Start();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length >= 4)
{
detailCollectedEvent.Set(); // 当textBox1的文本超过4位,发一个通知
}
}
AutoResetEvent detailCollectedEvent = new AutoResetEvent(false);
void YourThread()
{
MessageBox.Show("input you bank account details into the textbox");
detailCollectedEvent.WaitOne(); // 等候通知
MessageBox.Show("we will keep the secret.");
}
}
}C# 如何实现一个线程暂停和继续
C#窗体应用多线程示例
最新推荐文章于 2025-01-18 16:50:03 发布
本文介绍了一个使用C#编写的简单Windows窗体应用程序案例,演示了如何在用户输入达到一定长度时触发多线程处理,并通过AutoResetEvent同步线程。该程序在主线程之外创建了一个新线程,用于处理敏感操作。
693

被折叠的 条评论
为什么被折叠?



