1
Answer

TryEnter always return true in Timer Event

geo lam

geo lam

15y
3k
1
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)