COM Interop hang freezes the entire COM system. How to cancel a COM call

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- ?

+1
2

UPDATE - OP

, , :

(EXE), API (, IPC). EXE ( EXE) ... / - , "wrapper EXE", EXE... " " (, ) " EXE", , " EXE" ".

.NET, " EXE" " " ...

+3

DLL , . , , . , , ; .

COM- , , , . , , , . , , , .

/ , . . , . ..

+1

Source: https://habr.com/ru/post/1524345/


All Articles