日期:2014-05-18 浏览次数:20993 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
     
    public partial class Form1 : Form
    {
        private AutoResetEvent _SendEvent = null;
        public Form1()
        {
            InitializeComponent();
            _SendEvent = new AutoResetEvent(false);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ThreadStart oh=new ThreadStart (_send);
            Thread thread = new Thread(oh);
            thread.Start();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            _SendEvent.Set();
        }
        private void _send()
        {
            for (int index = 0; index < 10; index++)
            {
                _SendEvent.WaitOne();
                MessageBox.Show("Hello!");
                _SendEvent.WaitOne();
                MessageBox.Show("Bye");
                ……
            }
        }
    }
}