日期:2014-05-17  浏览次数:21071 次

怎么暂停程序执行,等待输入,输入完后继续
 	private void button1_Click(object sender, EventArgs e)
        {
            Thread threadstart = new Thread(new ThreadStart(Mystart));
            threadstart.IsBackground = true;
            threadstart.Start();
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Length == 4)
            {
                detailCollectedEvent.Set();
            }
        }
        AutoResetEvent detailCollectedEvent = new AutoResetEvent(false);
        private void Mystart()
        {
            Con();
            detailCollectedEvent.WaitOne();
            SendPost(richTextBox1.Text);
        }


为啥我在richTextBox中输入完文本,程序不继续执行.求指点

------解决方案--------------------
我这里测试可以。

按照你的程序修改的,新建一个窗体,添加一个RichTextBox一个Button,编写如下代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread threadstart = new Thread(new ThreadStart(Mystart));
            threadstart.IsBackground = true;
            threadstart.Start();
    &n