zoukankan      html  css  js  c++  java
  • c#如何实现一个线程暂停,等待用户输入文本后继续运行?

    事件通知是最佳方案,以前用一个while(xxx)来等待,后来发现会有一些问题:

    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.");
            }
        }
    }

  • 相关阅读:
    Spring Richclient — 企业级富客户端开发框架介绍,第 1 部分
    oracle的表名、字段名、constraint名的长度限制分别是多少?
    eclipse指定启动的jdk
    女人为什么爱攀比?
    Oracle一些常用的查询命令总结(持续更新)
    js冒泡事件之之之
    Aspose插件
    oracle11g导入到10g
    转:OpenCms 9.0.1汉化
    metasploit常用命令
  • 原文地址:https://www.cnblogs.com/Fooo/p/1363619.html
Copyright © 2011-2022 走看看