It's been several days that I'm on this problem without finding a solution...
I developed a macro for SolidWorks in VB.NET. It uses a COM object from a DLL that I developed in C++. The functions of this COM object take a long time to run (sometimes more than 30 seconds), and also make use of parallelized loops using OpenMP.
My problem is that when I run one of these functions, after ~10s, the program stops responding, and it freezes my UI! The DLL function is running and we can not send an update to the UI with a DoEvents()
...
I tried to put the function in a background worker but with COM objects it does not work. The other thing I tried is to make a background worker that accesses my process on a regular time interval to see if it responds. But when it stops responding, I can't force it to answer. The only solution that I found is to change the value of the registry key HungAppTimeout
, but this applies to everything on my machine whereas I want it applied to just my code.
Would you have a solution to avoid the "no answer"?
Example of code:
Public Sub StartfunctionCOM()
Dim Myclass as COMClass = new COMClass
Myclass.functiontakemanytime() 'time >10sec
End Sub
I have found a solution: I call the function DisableProcessWindowsGhosting
in my c++ code. It does not prevent the application from "not responding", but it will remove the automatic Windows response (ie the standard "Application does not respond anymore, wait or kill?" message box).