1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
static private ManualResetEvent _manualResetEvent;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
_manualResetEvent = new ManualResetEvent(false);
}
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("スレッドを開始します...");
Thread t = new Thread(DoWork);
t.Start();
}
private void button2_Click(object sender, EventArgs e)
{
Console.WriteLine("シグナル状態にしました...");
_manualResetEvent.Set();
}
private void DoWork()
{
Console.WriteLine(" シグナル状態になるのを待ちます...[Thread:" + Thread.CurrentThread.ManagedThreadId + "]");
_manualResetEvent.WaitOne();
Console.WriteLine(" シグナル状態になりました... [Thread:" + Thread.CurrentThread.ManagedThreadId + "]");
}
|