读书人

如何暂停程序执行等待输入输入完后

发布时间: 2013-10-02 13:10:38 作者: rapoo

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

 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();
}
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里面。

读书人网 >C#

热点推荐