I want to wait for the timer to end and return from the function. I tried this:
while(timer1.Enabled) { Application.DoEvents(); } return value;
But that did not work, and the function returned before the timer really ended. Here's the full function:
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer(); int[] foo() { do_something1(); int[] some_value; timer1.Interval = 1000; timer1.Tick += new EventHandler(delegate(object o, EventArgs ea) { if (browser.ReadyState == WebBrowserReadyState.Complete) { timer1.Stop(); baa(some_value); } }); timer1.Start(); while (timer1.Enabled) { Application.DoEvents(); } return some_value; }
source share