/// <summary> /// Event for Solve button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Bu_Solve_Click(object sender, EventArgs e) { if (ThreadFinished) // if we dont have a thread going { ThreadFinished = false; // prevent an other thread from sarting Bu_Solve.Enabled = false; // disable it for next time // Create a object of BackGroundMazeSolver withits own thread and give the thread to keep track // go to class BackGroundMazeSolver for more on CurrentBackGroundThread = BackGroundMazeSolver.StartNewThreadedSolver(Start, End, Display, Spaces, this, (int)NumUD_Speed.Value, out BackGroundSolver); } }
/// <summary> /// The the Solvers finish callback /// </summary> /// <param name="Solved">Did you sove it</param> /// <param name="Steps">The number of steps it took</param> void SolveDone(bool Solved, int Steps) { // set the background soolver to null so we dont try to change its speed BackGroundSolver = null; // write out a message or two if (Solved) { Invoke(new Action(() => { Lb_StepsReturn.Text = "The maze was solved in " + Steps + " Steps"; })); } else { Invoke(new Action(() => { Lb_StepsReturn.Text = "The maze has no solution"; })); } ThreadFinished = true; // let us create threads again }
/// <summary> /// Ish this class and gives it its own thread /// call in place of constructor /// you know think this is one of the first that ive not had a public constructor /// </summary> /// <param name="nStart">Set readonly point</param> /// <param name="nEnd">Set readonly End point</param> /// <param name="nDisplay">Set readonly Display to update</param> /// <param name="nSpaces">Set insh Maze Map to use</param> /// <param name="nParent">Set readonly Parent to update backto</param> /// <param name="InishSpeed">Set insh speed to Sinc with parent at start</param> /// <param name="ObjectReturn">This class we created</param> /// <returns>The thread created by this if youd like to keep track of</returns> static public Thread StartNewThreadedSolver(Point Start, Point End, CDrawer Display, SpaceStates[,] Spaces, MazeSolver Parent, int inishSpeed, out BackGroundMazeSolver ObjectReturn) { ObjectReturn = new BackGroundMazeSolver(Start, End, Display, Spaces, Parent, inishSpeed); Thread CurrentThread = new Thread(new ParameterizedThreadStart(StartThread), 600000); CurrentThread.IsBackground = true; CurrentThread.Start(ObjectReturn); return(CurrentThread); }
/// <summary> /// an internal function for steping into the objects main perpous needed so we can fit the peram threadstarst /// </summary> /// <param name="This">This refers to this from an outsiders point of view</param> static void StartThread(object This) { BackGroundMazeSolver SolverWorker = (BackGroundMazeSolver)This; SolverWorker.StartSolve(); }