/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/02 19:21:16	445
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/02 19:52:03	446
@@ -1044,6 +1044,7 @@
         }
         private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
         {
+            if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
             SearchDataTypes sdt = SearchArgs.DataType;
             bool unsigned = SearchArgs.IsUnsignedDataType;
             int Last_Whole_Percent_Done = 0;
@@ -1076,6 +1077,7 @@
                                         if (unsigned) { writer.WriteResult<UInt64>((uint)CurrentIndex, br.ReadUInt64()); }
                                         else { writer.WriteResult<Int64>((uint)CurrentIndex, br.ReadInt64()); } break;
                                 }
+                                if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
                             }
                             catch (EndOfStreamException) { }
                             double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
@@ -1088,6 +1090,7 @@
                                     resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
                                     Last_Whole_Percent_Done = int_percent_done;
                                 }
+                                if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
                             }
                             switch (sdt)
                             {
@@ -1109,6 +1112,7 @@
                     }
                 }
             }
+            if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
         }
         private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
         {
@@ -1145,6 +1149,7 @@
                     provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
                     provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
                     provider.CloseProvider();
+                    if (SearchWorkerThread.CancellationPending) { provider_st.Stop(); st.Stop(); writer.CancelRequest(); e.Result = true; return; }
                     writer.Dispose();
                 }
                 provider_st.Stop();
@@ -1725,13 +1730,17 @@
 
         private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {
-            if (!e.Cancelled)
+            try { if ((bool)e.Result) { logger.Warn.WriteLine("Search operation was cancelled."); resultsprogress.Value = 0; resultsprogress.Message = ""; return; } }
+            catch (InvalidCastException) { }
+            try
             {
-                Stopwatch st = (e.Result as Stopwatch);
+                Stopwatch st = (Stopwatch)e.Result;
                 st.Stop();
                 logger.Profiler.WriteLine("Search took {0} seconds, overall, to complete.", st.Elapsed.TotalSeconds);
             }
-            
+            catch (InvalidCastException) { }
+            catch (Exception ex) { throw ex; }
+
             resultsprogress.Value = 100;
             bool unsigned = SearchArgs.IsUnsignedDataType;
             using (SearchResultReader reader = new SearchResultReader(SearchGuid))

 

  ViewVC Help
Powered by ViewVC 1.1.22