I have a stream that adds points to the zedgraph component for a certain amount of time. I need to pause adding points when I click the checkbox, and then resume adding them when I click the checkbox again. Below is what I have for the stream:
public class myThread{
ManualResetEvent pauseResumeThread = new ManualResetEvent(true);
public void threadHeartrateGraph()
{
for (int k = 15; k < _hr.Length; k++)
{
pauseResumeThread.WaitOne();
if (HRDataSummary.threadPause == true)
{
break;
}
x = k;
y = _hr[k];
list1.Add(x, y);
_displayHRGraph.Invoke(list1, graph_HeartRate, _GraphName[0]);
graph_HeartRate.XAxis.Scale.Min = k-14;
graph_HeartRate.XAxis.Scale.Max = k+1;
Thread.Sleep(_interval * 1000);
}
}
catch (NullReferenceException)
{
}
}
public void play()
{
pauseResumeThread.Set();
}
public void pause()
{
pauseResumeThread.Reset();
}
}
And then, I called to play and paused the stream from the checkbox.
private void checkBoxPause_CheckedChanged(object sender, EventArgs e)
{
if(checkBoxPause.Checked == true)
{
checkBoxPause.Text = "Play >";
myThread mythread = new myThread();
Thread pause = new Thread(mythread.pause);
pause.Start();
}
if (checkBoxPause.Checked == false)
{
checkBoxPause.Text = "Pause ||";
myThread mythread = new myThread();
Thread play = new Thread(mythread.play);
play.Start();
}
}
What am I missing? Or is it a misuse of ManualResetEvent?
source
share