geo lam

geo lam

  • NA
  • 8
  • 0

TryEnter always return true in Timer Event

May 12 2009 11:35 PM
Dear All, That's strange that when I use TryEnter in Timer event which triggers every 1 sec, the TryEnter() always returns true. Why there is such an error? public partial class Form1 : Form { private object BlockingObj = new object(); private void timer1_Tick(object sender, EventArgs e) { bool ret = System.Threading.Monitor.TryEnter(BlockingObj, 1); if (ret){ try { DialogResult result = MessageBox.Show("test", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); } finally { System.Threading.Monitor.Exit(BlockingObj); } } } }

Answers (1)