|
|
|
@ -7,6 +7,7 @@ using System.Reflection;
@@ -7,6 +7,7 @@ using System.Reflection;
|
|
|
|
|
using System.Windows.Forms; |
|
|
|
|
using System.Windows.Threading; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
|
using Debugger.AddIn.Pads.Controls; |
|
|
|
|
using ICSharpCode.Core; |
|
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
@ -41,46 +42,39 @@ namespace Debugger.AddIn.TreeModel
@@ -41,46 +42,39 @@ namespace Debugger.AddIn.TreeModel
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work) |
|
|
|
|
public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work, Action<T> failAction = null) |
|
|
|
|
{ |
|
|
|
|
long debuggeeStateWhenEnqueued = process.DebuggeeState; |
|
|
|
|
|
|
|
|
|
dispatcher.BeginInvoke( |
|
|
|
|
DispatcherPriority.Normal, |
|
|
|
|
(Action)delegate { ProcessItems(process, dispatcher, 0, items, work, debuggeeStateWhenEnqueued); } |
|
|
|
|
); |
|
|
|
|
foreach (T item in items) { |
|
|
|
|
var workItem = item; |
|
|
|
|
dispatcher.BeginInvoke( |
|
|
|
|
DispatcherPriority.Normal, |
|
|
|
|
(Action)delegate { |
|
|
|
|
if (!ProcessItem(process, workItem, work, debuggeeStateWhenEnqueued) && failAction != null) |
|
|
|
|
failAction(workItem); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ProcessItems<T>(Process process, Dispatcher dispatcher, int startIndex, IList<T> items, Action<T> work, long debuggeeStateWhenEnqueued) |
|
|
|
|
static bool ProcessItem<T>(Process process, T item, Action<T> work, long debuggeeStateWhenEnqueued) |
|
|
|
|
{ |
|
|
|
|
var watch = new System.Diagnostics.Stopwatch(); |
|
|
|
|
watch.Start(); |
|
|
|
|
|
|
|
|
|
for (int i = startIndex; i < items.Count; i++) { |
|
|
|
|
int index = i; |
|
|
|
|
if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) { |
|
|
|
|
try { |
|
|
|
|
// Do the work, this may recursively enqueue more work
|
|
|
|
|
work(items[index]); |
|
|
|
|
} catch (System.Exception ex) { |
|
|
|
|
if (process == null || process.HasExited) { |
|
|
|
|
// Process unexpectedly exited - silently ignore
|
|
|
|
|
} else { |
|
|
|
|
MessageService.ShowException(ex); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) { |
|
|
|
|
try { |
|
|
|
|
// Do the work, this may recursively enqueue more work
|
|
|
|
|
work(item); |
|
|
|
|
return true; |
|
|
|
|
} catch (System.Exception ex) { |
|
|
|
|
if (process == null || process.HasExited) { |
|
|
|
|
// Process unexpectedly exited - silently ignore
|
|
|
|
|
} else { |
|
|
|
|
MessageService.ShowException(ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if we are too slow move to background
|
|
|
|
|
if (watch.ElapsedMilliseconds > 100) { |
|
|
|
|
dispatcher.BeginInvoke( |
|
|
|
|
DispatcherPriority.Background, |
|
|
|
|
(Action)delegate { ProcessItems(process, dispatcher, index + 1, items, work, debuggeeStateWhenEnqueued); } |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
SD.Log.Error("ProcessItem cancelled", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|