c#如何实现一个线程暂停,等待用户输入文本后继续运行?
2012-06-21 03:49
871 查看
可以用事件通知:
C# code
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# code
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#如何实现一个线程暂停,等待用户输入文本后继续运行?
- C# 如何实现一个线程暂停和继续
- C# 如何实现一个线程暂停和继续 - 转
- 批处理如何做到等待用户输入一个值(dos命令行)
- 如何实现使得一个普通用户以root身份运行命令和如何使用sudo命令?
- 1, 编写程序,当用户在文本框中输入内容之后,单机不同的按钮,能够把文半框中的内容粘贴到文本区中。“重置”按钮实现将文本框和文本区中的内容清空。界面上的文本区只能显示内容,不能让用户输入文本。运行结果
- grunt实现用户输入及继续运行
- 实现一个简单的菜单程序,运行时显示"Menu:A(dd) D(elete) S(ort) Q(uit),Select one: "提示用户输入。输入A、D、S时分别提示"数据已经增加、删除、排序"
- 自己实现一个SQL解析引擎 功能:将用户输入的SQL语句序列转换为一个可执行的操作序列,并返回查询的结果集。 SQL的解析引擎包括查询编译与查询优化和查询的运行,主要包括3个步骤: 查询分析
- CountDownLatch实现主线程等待所有子线程运行结束后再继续执行的实现
- 9.11练习:文件访问,写一个逐页显示文本文件的程序,提示输入一个文件名,每次显示文本文件的25行,暂停并向用户提示“按任意键继续”,按键后继续执行。
- 如何实现多个线程写、一个线程读的队列,并且所有线程间不需要等待同步
- 如何等待一个线程完成后才继续执行之后的操作
- 如何实现使得一个普通用户以root身份运行命令
- 如何实现使得一个普通用户以root身份运行命令
- DataGrid动态生成模板列,模板列里面有一个TextBox,如何获取用户在TextBox里面输入的值啊?
- 一个操作系统的实现(1):分析linux下如何运行一个执行文件
- 实现功能:弹出一个DIV层提示等待信息,这个时候禁用用户操作页面中的其他内容
- 如何使用CSS3实现一个平滑的3D文本标题