If I call TerminateThread from C ++ code, then later I get FatalExecutionEngineError MDA later. This error occurs when I perform various operations on strings (i.e. Concat). The code below simply shows how to reproduce it.
Why is this happening? How can I fix it and use TerminateThread?
thanks
Error:
FatalExecutionEngineError was detected Message: The runtime has encountered a fatal error. The address of the error was at 0x7880bb35, on thread 0x18f0. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
C ++ Code:
Module.cpp:
#include "ThreadModule.h" using namespace ThreadModule; DWORD WINAPI workThread(LPVOID lpParam) { while(1) { System::Threading::Thread::Sleep(5); printf("."); } return 0; } bool Module::StartThread() { handle = CreateThread( NULL, 0, workThread, NULL, 0, &threadIdInput); return true; } bool Module::StopThread() { TerminateThread(handle, 0); handle = NULL; return true; }
C # code:
static void Main(string[] args) { Module module = new Module(); module.StartThread(); string s = ""; for (int i = 0; i < 10000; i++) { s += i.ToString(); } module.StopThread(); s = ""; for (int i = 0; i < 10000; i++) { s += i.ToString();
source share