public partial class Form1 : Form
{
static AutoResetEvent autoEvent = new AutoResetEvent(false);
public void button1_Click(object sender, EventArgs e)
{
Class1 c = new Class1();
Task t = new Task(()=>y());
t.start();
Task t2 = new Task(()=>c.run());
t2.start();
}
public void y()
{
MessageBox.Show("Y called");
autoEvent.Set();
}
}
public class1
{
void run()
{
autoEvent.WaitOne();
MessageBox.Show("Class1 run Called after Form1");
}
}
ÀÌ·±½ÄÀ¸·Î Äڵ带 ±¸¼ºÇÏ°í ½Í½À´Ï´Ù.
¸ÞÀνº·¹µåÀÇ ÇÔ¼ö°¡ Á¾·áµÇ¸é ´Ù¸¥Å¬·¡½ºÀÇ ÇÔ¼ö°¡ ¿¬°áµÈ Task¸¦ È£ÃâÇÏ·Á°íÇϴµ¥
´Ù¸¥ Ŭ·¡½º¿¡¼ ¾î¶»°ÔÇϸé AutoReserEvent¸¦ ¾×¼¼½ºÇÒ ¼ö ÀÖÀ»±î¿ä? | |
|
Class1 »ý¼ºÀÚ¿¡¼
Class Class1
{
Public Form1 mainForm;
public Class1(Form1 parentForm)
{
this.mainForm = parentForm;
}
public void run()
{
this.mainForm.autoEvent.WaitOne();
// ÀÛ¾÷
}
}