Home→Forums→MonoBrick EV3 Firmware→Ending the Program by pressing the Escape-Button→Reply To: Ending the Program by pressing the Escape-Button
February 6, 2014 at 09:34
#3942
Jacek S
Participant
Hi,
Your program never ends because you must start main loop in separate thread and place wait event at the end of main thread.
using System.Threading;
using System.Threading.Tasks;
using MonoBrickFirmware.UserInput;
namespace EV3Program
{
internal class Program
{
private static void Main(string[] args)
{
ManualResetEvent terminateProgram = new ManualResetEvent(false);
ButtonEvents buts = new ButtonEvents();
buts.EscapePressed += () =>
{
terminateProgram.Set();
};
var myLogic = new MyLogic();
Task.Factory.StartNew(() => myLogic.Run());
terminateProgram.WaitOne();
}
}
}
Jacek
Follow