I use a third-party DLL that opens through the COM Interop shell. However, one of the COM calls often hangs (never returns at least). To at least make my code a little more reliable, I wrapped the call asynchronously ( _getDeviceInfoWaiteris ManualResetEvent)
var backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork +=
(sender, eventArgs) =>
{
var deviceInfo = _myCom.get_DeviceInfo(0);
_serialNumber = deviceInfo.SerialNumber;
_getDeviceInfoWaiter.Set();
};
backgroundWorker.RunWorkerAsync();
var waitFifteenSecondsForGetInfo = new TimeSpan(0, 0, 0, 15);
_getDeviceInfoWaiter.WaitOne(waitFifteenSecondsForGetInfo, true);
if(String.IsNullOrEmpty(_serialNumber))
throw new ArgumentNullException("Null or empty serial number. " +
"This is most likely due to the get_DeviceInfo(0) COM call freezing.");
However, the next call to any COM component will slow down the code. Is there something I don’t think about, or is there a way to keep my main stream from dying?
UPDATE
, COM-, , , . , , COM- , ( COM , )
2
COM-. - , var deviceInfo = _myCom.get_DeviceInfo(0); . , " 15 "
COM- ?