wpf - Handling AccessViolation exception in try catch c# -
how catch accessviolation exception in try-catch block:
here code below:
public static bp getbloodpressure(string vendorid, string productid) { bp result = new bp(); try { getbpdata bpreadings = new getbpdata(); uint16 vendorid = convert.touint16(vendorid, 16); uint16 productid = convert.touint16(productid, 16); if (healthmonitordata.hiddatatap_getbloodpressure(vendorid, productid, ref bpreadings)) // error here { if (bpreadings.ucsystolic == 0 && bpreadings.ucdiastolic == 0 && bpreadings.deviceid1 == 0 && bpreadings.deviceid2 == 0 && bpreadings.ucpulse == 0) { result = null; } else { result.ucsystolic = bpreadings.ucsystolic; result.ucdiastolic = bpreadings.ucdiastolic; result.ucpulse = bpreadings.ucpulse; result.deviceid1 = bpreadings.deviceid1; result.deviceid2 = bpreadings.deviceid2; } } } catch (exception ex) { } return result; } i importing 1 dll read blood pressure values device. have try catch exception control not go beyond "if" statement access violation exception coming.
kindly suggest?
thanks
handling of accessviolationexceptions , other corrupted state exceptions has been changed in .net 4. should not catch these exceptions, runtime has been changed reflect this. if need catch these, must annotate code handledprocesscorruptedstateexceptions attribute.
please keep in mind, behavior changed reason. applications not able handle these exceptions in meaningful way , should not catch them.
Comments
Post a Comment