//Get ready to scan the memory for the string value. public void StartScanForString(string stringValue) { //Check if the thread is already defined or not. if (thread != null) { //If the thread is already defined and is Alive, if (thread.IsAlive) { //raise the event that shows that the last scan task is canceled //(because a new task is going to be started as wanted), ScanCanceledEventArgs cancelEventArgs = new ScanCanceledEventArgs(); ScanCanceled(this, cancelEventArgs); //and then abort the alive thread and so cancel last scan task. thread.Abort(); } } //Set the thread object as a new instant of the Thread class and pass //a new ParameterizedThreadStart class object with the needed method passed to it //to run in the new thread. thread = new Thread(new ParameterizedThreadStart(StringScanner)); //Start the new thread and set the 32 bit value to look for. thread.Start(stringValue); }
//Cancel the scan started. public void CancelScan() { //Raise the event that shows that the last scan task is canceled as user asked, ScanCanceledEventArgs cancelEventArgs = new ScanCanceledEventArgs(); ScanCanceled(this, cancelEventArgs); //and then abort the thread that scanes the memory. thread.Abort(); }