diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs index 002f65e20c..88ae0a5303 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs @@ -47,6 +47,14 @@ namespace Debugger } } + internal bool ContainsThread(ICorDebugThread corThread) + { + foreach(Thread thread in threadCollection) { + if (thread.CorThread == corThread) return true; + } + return false; + } + internal Thread GetThread(ICorDebugThread corThread) { foreach(Thread thread in threadCollection) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs index 68f690050b..cbcb1565e8 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs @@ -409,10 +409,17 @@ namespace Debugger public void ExitThread(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread) { - // It seems that ICorDebugThread is still not dead and can be used - EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, pThread); - - process.GetThread(pThread).NotifyExited(); + // ICorDebugThread is still not dead and can be used for some operations + if (process.ContainsThread(pThread)) { + EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, pThread); + + process.GetThread(pThread).NotifyExited(); + } else { + EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, process.CorProcess); + + // TODO: Investigate + process.TraceMessage("ERROR: Thread does not exist " + pThread.ID); + } try { ExitCallback();