static void Main(string[] args) { var terminateProgram = new ManualResetEvent(false); var cubeSolver = new CubeSolver(); var buts = new ButtonEvents(); buts.EscapePressed += () => terminateProgram.Set(); Task.Factory.StartNew(cubeSolver.Run); terminateProgram.WaitOne(); cubeSolver.Stop(); //var solution = Search.solution(Tools.randomCube(), 26, false); }