I'm working with SecureGen U20 finger print scanner - the SDK is in C# but the dll working with the device are in C++ which is unmanaged and cause me problems
the application crashes if the device is repeatedly start scanning and only shows this error

My question is not about the device - how do i prevent from any errors in c++ to crash my application , I have of course try catch and all of that the process of scanning is a different thread
This is a separated thread called
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
[System.Security.SecurityCritical]
private void captureFingure()
{
WriteLog("Started captureFingure");
try
{
int size = 0;
while (m_DeviceScanning)
{
byte[] fp_image = new byte[m_ImageWidth * m_ImageHeight];
int getImageExErrorCode = m_FingerprintManager.GetImage(fp_image);
if (getImageExErrorCode == (int)SGFPMError.ERROR_NONE)
{
WriteLog($"captureFingure Finger Captured with code {((SGFPMError)getImageExErrorCode).ToString()}");
int maxTemplateSizeError = m_FingerprintManager.GetMaxTemplateSize(ref size);
byte[] fp_template = new byte[size];
int createTemplateErrorCode = m_FingerprintManager.CreateTemplate(fp_image, fp_template);
if (createTemplateErrorCode == (int)SGFPMError.ERROR_NONE)
{
WriteLog($"captureFingure Created template with code {((SGFPMError)createTemplateErrorCode).ToString()}");
Stop();
OnFingerprintScanned?.Invoke(this, fp_template);
break;
}
}
else
{
Thread.Sleep(500);
}
}
}
catch {
WriteLog($"Exception thrown in captureFingure: Non-CLS compliant exception caught.");
}
WriteLog("Ended captureFingure");
}
it's seems the line int getImageExErrorCode = m_FingerprintManager.GetImage(fp_image); causing the error
is there a way to NOT crashing the application? - I don't care if there is error in c++ , I can just try to reactivate it