對“xxx”類型的已垃圾回收委托進行了回調。這可能會導致應用程序崩潰、損壞和數據丟失。向非托管代碼傳遞委托時,托管應用程序必須讓這些委托保持活動狀態,直到確信不會再次調用它們。


在程序中調用C++鏈接庫中的回調函由於沒有考慮生命周期,直接寫委托回隨機的被gc給回收掉導致報這個錯誤

錯誤的程序:

private void InitPlateIdentify()
{
   try
   { 
        if (string.IsNullOrEmpty(sPlateIP))return;
        handle = Dbvt_JpegCreateCamera(handle);
        Dbvt_JpegSetCameraCallBack(handle,DBVT_JpegSave,DBVT_GetSerialData,Dbvt_SetDevicesError);
        if (!Dbvt_JpegConnectDataCamera(handle, sPlateIP))
                    MessageBox.Show("打開車牌識別失敗");
       }
       catch (Exception ex)
       {
           MessageBox.Show("打開車牌識別失敗");
           Log.log("錯誤InitPlateIdentify:" + ex.ToString());
       }
 }

正確的程序:

private CameraJpegCallBackFunc fMSGCallBack;
private void InitPlateIdentify()
{
     try
     {
          if (string.IsNullOrEmpty(sPlateIP)) return;
          this.fMSGCallBack = this.DBVT_JpegSave;
          handle = Dbvt_JpegCreateCamera(handle);
          Dbvt_JpegSetCameraCallBack(handle, this.fMSGCallBack, DBVT_GetSerialData, Dbvt_SetDevicesError);
           if (!Dbvt_JpegConnectDataCamera(handle, sPlateIP))
                    MessageBox.Show("打開車牌識別失敗");
       }
       catch (Exception ex)
       {
           MessageBox.Show("打開車牌識別失敗");
                Log.log("錯誤InitPlateIdentify:" + ex.ToString());

        }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM