private void button4_Click(object sender, EventArgs e)
{
Mutex m = new Mutex();
autoevent = new AutoResetEvent(false);
Thread t = new Thread(delegate()
{
Thread.Sleep(500);
for (int i = 0; i < 50000; i++)
{
m.WaitOne();
try
{
label1.Invoke
(
(MethodInvoker)
delegate
{
label1.Text = i.ToString();
}
);
}
finally
{
m.ReleaseMutex();
}
}
});
t.Start();
Thread t2 = new Thread(delegate()
{
for (int i = 0; i < 50000; i++)
{
m.WaitOne();
try
{
label1.Invoke((System.Action)delegate()
{
label1.Text = i.ToString();
});
}
finally
{
m.ReleaseMutex();
}
}
});
t2.Start();
}