Ok I have a simulator which consists of some methods and a timer. I am starting the timer here :
private void StartSimulation(object sender,EventArgs e)
{
while(execList.Count != 0)
{
Assign(MF,Mpre);
retCT = ChooseTransition(execList);
ttoexec = retCT[1];
this.time = retCT[0];
timer.Start();
// I need to stop execution of this method here untill timer stops ticking
ExecuteTransition(ttoexec);
execList.Remove(ttoexec);
}
}
And the timer method is like :
private void Timer_Tick(object sender,EventArgs e)
{
--time;
++k;
output.Add("t.u : " + k + " " + "M = [" + MF.GetRowVal() + "];");
if (time == 0)
{
timer.Stop();
}
}
variable time is of type int and holds the number of seconds time needs to tick(is time * 1000 ms of the interval time of timer). Note that in StartSimulation method I am setting time with a value from an array.
Update
I am using a System.Windows.Forms.Timer
I want my StartSimulation() to stop executing until timer is stopped (until the execution of timer.Stop() in Timer_Tick).The output is a list of strings , which in the end I will write in a txt file .
The issue now is that the execution of StartSimulation() is going in same time as the timer ticks , therefore output list have only 1 element (that one I insert in the beginning of StartSimulation() code which I didn't paste it here).
So I open the txt file , write in it, close it and timer is still going. The execution of StartSimulation should stop when timer.Start() method is invoked
$"t.u : {k} M = [{MF.GetRowVal()}];"- TheGeneral