Browse Source

Fix some dynamic issues

pull/15/head
Eusebiu Marcu 15 years ago committed by Daniel Grunwald
parent
commit
d10ec2a093
  1. 30
      src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.cs

30
src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.cs

@ -3,7 +3,6 @@
using System; using System;
using System.Dynamic; using System.Dynamic;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
@ -11,6 +10,8 @@ using Debugger;
using Debugger.AddIn.Pads.Controls; using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.TreeModel; using Debugger.AddIn.TreeModel;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Services;
using Exception = System.Exception; using Exception = System.Exception;
using Thread = Debugger.Thread; using Thread = Debugger.Thread;
@ -113,8 +114,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
if (debuggedProcess.IsPaused) { if (debuggedProcess.IsPaused) {
if (debuggedProcess != null) { if (debuggedProcess != null) {
dynamic obj = runningThreadsList.SelectedItems[0]; dynamic obj = runningThreadsList.SelectedItems[0];
debuggedProcess.SelectedThread = (Thread)(obj.Tag); Thread thread = (Thread)(obj.Tag);
debuggedProcess.OnPaused(); // Force refresh of pads debuggedProcess.SelectedThread = thread;
debuggedProcess.OnPaused();
} }
} else { } else {
MessageService.ShowMessage("${res:MainWindow.Windows.Debug.Threads.CannotSwitchWhileRunning}", "${res:MainWindow.Windows.Debug.Threads.ThreadSwitch}"); MessageService.ShowMessage("${res:MainWindow.Windows.Debug.Threads.CannotSwitchWhileRunning}", "${res:MainWindow.Windows.Debug.Threads.ThreadSwitch}");
@ -123,6 +125,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
void AddThread(Thread thread) void AddThread(Thread thread)
{ {
if (thread == null) return;
// remove the object if exists // remove the object if exists
RemoveThread(thread); RemoveThread(thread);
@ -133,16 +137,17 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
thread.NameChanged += delegate { thread.NameChanged += delegate {
RefreshItem(obj); RefreshItem(obj);
}; };
thread.Exited += delegate { thread.Exited += (s, e) => RemoveThread(e.Thread);
RemoveThread(obj);
};
} }
void RefreshItem(ExpandoObject obj) void RefreshItem(ExpandoObject obj)
{ {
dynamic item = obj; dynamic item = obj;
if (item == null) return;
var thread = item.Tag as Thread; var thread = item.Tag as Thread;
if (thread == null) return;
item.ID = thread.ID; item.ID = thread.ID;
item.Tag = thread; item.Tag = thread;
StackFrame location = null; StackFrame location = null;
@ -156,19 +161,19 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
} }
switch (thread.Priority) { switch (thread.Priority) {
case ThreadPriority.Highest: case System.Threading.ThreadPriority.Highest:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Highest"); item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Highest");
break; break;
case ThreadPriority.AboveNormal: case System.Threading.ThreadPriority.AboveNormal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.AboveNormal"); item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.AboveNormal");
break; break;
case ThreadPriority.Normal: case System.Threading.ThreadPriority.Normal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Normal"); item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Normal");
break; break;
case ThreadPriority.BelowNormal: case System.Threading.ThreadPriority.BelowNormal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.BelowNormal"); item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.BelowNormal");
break; break;
case ThreadPriority.Lowest: case System.Threading.ThreadPriority.Lowest:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Lowest"); item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Lowest");
break; break;
default: default:
@ -180,6 +185,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
void RemoveThread(Thread thread) void RemoveThread(Thread thread)
{ {
if (thread == null)
return;
foreach (dynamic item in runningThreadsList.ItemCollection) { foreach (dynamic item in runningThreadsList.ItemCollection) {
if (thread.ID == item.ID) { if (thread.ID == item.ID) {
runningThreadsList.ItemCollection.Remove(item); runningThreadsList.ItemCollection.Remove(item);

Loading…
Cancel
Save