How do I let main thread wait for the Timer.timer
Posted
by Kelvin
on Stack Overflow
See other posts from Stack Overflow
or by Kelvin
Published on 2010-05-20T03:24:55Z
Indexed on
2010/05/20
3:30 UTC
Read the original article
Hit count: 499
c#
Hi I am using System.Timer.Timer
I always get NULL after running my programme and it only works if I add this.sleep(6000). Suppose the reason is the main thread ends but the timer hasn't finished ... Here is the class and I call the class from my main form.
Class class1
{
string finalResult = "";
public string getNumber()
{
RunTimer();
return finalResult;
}
pubic void RunTimer ()
{
timer = new System.Timers.Timer(6000);
timer.Interval = 1000;
timer.Elapsed += new System.Timers.ElapsedEventHandler(cal);
timer.Start();
}
private void cal(object sender,System.Timers.ElapsedEventArgs e)
{
finalResult = READFROMCOMPORT;
}
}
© Stack Overflow or respective owner