I have an operation via While that i want to Freeze:
do
{
ManualResetEvent.Reset(); // Here i want to wait
// Here i am doing my stuff...
}
while (some boolean value);
}
My ManualResetEvent :
private static ManualResetEvent _manualResetEvent;
public static ManualResetEvent ManualResetEvent
{
get { return _manualResetEvent; }
set { _manualResetEvent = value; }
}
ManualResetEvent = new ManualResetEvent(false);
In some point in my code via Button i just want to freeze my operation:
private void btnPause_Click(object sender, RoutedEventArgs e)
{
ManualResetEvent.WaitOne();
}
Is this the right way to do that ?
You have your two functions backwards. The loop you want to wait needs to use the
.WaitOne(). Also, if you want it to run at the start you need to initialize the reset event totrueinit
loop
elsewhere