/// <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) { // BackGroundLoader LoaderWorker = (BackGroundLoader)This; LoaderWorker.Load(); }
/// <summary> /// Inishizes a new instance of this class form the private constructor and then starts /// a new background thread for it to run in. /// </summary> /// <param name="nDisplay">The CDrawer display box we use to render</param> /// <param name="nPath">The path we will want to load an image from</param> /// <param name="nMaze">The parent form</param> /// <param name="ObjectReturn">The a out for the parent so you can call back to this object if necassary</param> /// <returns>The thread started for if you would like to keep track of it</returns> static public Thread StartNewThreadedLoader(CDrawer nDisplay, string nPath, MazeSolver nMaze, out BackGroundLoader ObjectReturn) { ObjectReturn = new BackGroundLoader(nDisplay, nPath, nMaze); Thread CurrentThread = new Thread(new ParameterizedThreadStart(StartThread)); CurrentThread.IsBackground = true; CurrentThread.Start(ObjectReturn); return(CurrentThread); }
// IPORTANT Note : this is a partial Class // the Utility funtions incuding the constructor is in found in the MazeSolverUtil.cs /// <summary> /// Event for load button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Bu_Load_Click(object sender, EventArgs e) { Text = "Load Bitmap to solve"; // create insh a Dilog for opening a file and set it to what we need OpenFileDialog FileFinder = new OpenFileDialog(); FileFinder.InitialDirectory = Path.GetFullPath(Environment.CurrentDirectory + @"..\..\..\"); FileFinder.Multiselect = false; FileFinder.Filter = "Bitmap Files|*.bmp|All Files|*.*"; if (FileFinder.ShowDialog() == DialogResult.OK && ThreadFinished) { ThreadFinished = false; // prevent an other thread from sarting Bu_Solve.Enabled = false; // alow solve events // Create a object of BackGroundLoader withits own thread and give the thread to keep track // go to class BackGroundLoader for more on CurrentBackGroundThread = BackGroundLoader.StartNewThreadedLoader(Display, FileFinder.FileName, this, out backGroundLoader); } }