I have been trying to modify an app developed by other in past ...
this app does online trading ( using api developed for C#)..so basically i have the app structure where i set few configuration paramter which user can check or uncheck and there is start and stop button
on clicking start button..i am creating a thread by passing function which will do all aping and other stuff and assigning it to main form class
betbot _mybot = this; # mybot is form class
this.main_thread = new Thread(new ThreadStart(_mybot.aping_function);
this.main_thread.Start();
and on clicking stop button,,,app is simply suspending the thread
this.main_thread.Suspend()
now the app stops and only way to resume the app function (aping) is to press start button and relaunch thread..
As a new feature , i want this thread to stop and restart automatically ..every time it hits certain stop loss and start over...but i couldn't do it
what i have tired is ManualResetEvent as following
private static ManualResetEvent mrse = new ManualResetEvent(true);
when certain event matches in aping_function method i do mrse.reset() and mrse.set()..but that seems to have not effect( not restarting completely)
if (stop_loss_condition_met)
{
this.Print1("Bot Is stopped Automatically");
mrse.Reset();
this.Print1("Bot Is re-started Automatically");
mrse.Set();
}
how can i achieve this