怎么暂停程序执行,等待输入,输入完后继续

qiouqfz 2013-09-28 05:34:27
 	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中输入完文本,程序不继续执行.求指点
...全文
437 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
E次奥 2013-09-29
  • 打赏
  • 举报
回复
因为计算机太笨了,你让他干什么他才干什么!
  • 打赏
  • 举报
回复
这个要给页上的控件回传属性赋值么
threenewbee 2013-09-28
  • 打赏
  • 举报
回复
我这里测试可以。 按照你的程序修改的,新建一个窗体,添加一个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();
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Length == 4)
            {
                detailCollectedEvent.Set();
            }
        }
        AutoResetEvent detailCollectedEvent = new AutoResetEvent(false);
        private void Mystart()
        {
            Step1();
            detailCollectedEvent.WaitOne();
            Step2();
        }

        private void Step2()
        {
            Invoke(new Action(() => this.Text = "2"));
        }

        private void Step1()
        {
            Invoke(new Action(() => this.Text = "1"));
        }
    }
}
看看问题是不是出在con sendpost里面。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧