How do I let main thread suspend and wait for the System.Timer.Timer running
- by Kelvin
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(30000);
timer.Interval = 1000;
timer.Elapsed += new System.Timers.ElapsedEventHandler(cal);
timer.Start();
}
private void cal(object sender,System.Timers.ElapsedEventArgs e)
{
finalResult += READFROMCOMPORT;
}
}