以下代码先点button1,会先弹出messagebox, 再点button2,没有反应,关了messagebox,才会再次弹出
private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(this.testLock)); t.Start(); } private void button2_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(this.testLock)); t.Start(); } private void button3_Click(object sender, EventArgs e) { testLock(); } private void testLock() { lock (this) { MessageBox.Show("code locked"); } }
原文:http://www.cnblogs.com/dlzh/p/7892705.html