程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> process-C#程序關閉,進程還在運行

process-C#程序關閉,進程還在運行

編輯:編程綜合問答
C#程序關閉,進程還在運行

寫了一個C#的程序,調用了一個C++的dll,在C++的DLLMain中下面這樣寫的,特意在DLL_PROCESS_DETACH中關閉了線程,但那個MessageBox在關閉C#程序時並沒有彈出來,是不是意味著我所有在dll中開的線程都沒關閉?為什麼會這樣呢?


BOOL APIENTRY DllMain( HMODULE hModule,             // handle to DLL module
                       DWORD  ul_reason_for_call,   // reason for calling function
                       LPVOID lpReserved            // reserved
                     )
{
    // Perform actions based on the reason for calling.
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:        // Initialize once for each new process.Return FALSE to fail DLL load.
        {

            SetDllNCCallback(rtm_InterpStartEnd);
            SendNCDriverUserDecodeEvent();

            pctr_dataShm = (LPCTRDATA)malloc(sizeof(Shmctr_data));//初始化全局控制變量
            if(pctr_dataShm == NULL)
            {
                MessageBox(NULL,TEXT("can not alloc heapmemory in pctr_dataShm"),TEXT("Interpolation Error"),NULL);
                return 1;
            }

            hrtm_PositCtrl_Trd = CreateThread(NULL, 0, rtm_PositCtrl_Trd, NULL,CREATE_SUSPENDED, NULL);
            SetThreadPriority(hrtm_PositCtrl_Trd, THREAD_PRIORITY_TIME_CRITICAL);
            ResumeThread(hrtm_PositCtrl_Trd);

            hrtm_VelCtrl_Trd = CreateThread(NULL, 0, rtm_VelCtrl_Trd, NULL,CREATE_SUSPENDED, NULL);
            SetThreadPriority(hrtm_VelCtrl_Trd, THREAD_PRIORITY_HIGHEST);
            ResumeThread(hrtm_VelCtrl_Trd);

            hrtm_DecodFifo_Trd = CreateThread(NULL, 0, rtm_DecodFifo_Trd, NULL,CREATE_SUSPENDED, NULL);
            SetThreadPriority(hrtm_DecodFifo_Trd, THREAD_PRIORITY_ABOVE_NORMAL);
            ResumeThread(hrtm_DecodFifo_Trd);

            hrtm_Intrp_Trd = CreateThread(NULL, 0, rtm_Intrp_Trd, NULL,CREATE_SUSPENDED, NULL);
            SetThreadPriority(hrtm_Intrp_Trd, THREAD_PRIORITY_NORMAL);
            ResumeThread(hrtm_Intrp_Trd);

            hrtm_Prd_2ms = CreateThread(NULL,0,rtm_Prd_2ms,0,0,NULL);

            break;
        }

    case DLL_THREAD_ATTACH:
        //MessageBox(NULL,TEXT("Enter DLL_THREAD_ATTACH"),TEXT("Interpolation Inform"),NULL);
        break;
    case DLL_THREAD_DETACH:
        //MessageBox(NULL,TEXT("Enter DLL_THREAD_DETACH"),TEXT("Interpolation Inform"),NULL);
        break;
    case DLL_PROCESS_DETACH:
        CloseHandle(hrtm_PositCtrl_Trd);

        free(pctr_dataShm); //釋放全局控制量
        pctr_dataShm = NULL;
        CloseHandle(hrtm_PositCtrl_Trd);
        CloseHandle(hrtm_VelCtrl_Trd);
        CloseHandle(hrtm_DecodFifo_Trd);
        CloseHandle(hrtm_Intrp_Trd);
        CloseHandle(hrtm_Prd_2ms);

        MessageBox(NULL,TEXT("Leave Interpolation dll"),TEXT("Interpolation Inform"),NULL);
        break;
    }
    return TRUE;
}

最佳回答:



Process.GetCurrentProcess().Kill();
關閉下看看

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved