在程序中调用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());
}
}
原文链接: https://www.cnblogs.com/zhx7803/p/dui-xxx-lei-xing-de-yi-la-ji-hui-shou-wei-tuo-jin-.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/224044
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!