0

The C# console application running .NET 4.5.2 (app1) opens a COM application (app2) and does some work with that app2's API. So far all of the work is successful, but sometimes when app1 attempts to close app2, app2 hangs permanently.

If the process for app2 is ended with task manager then app1 reports access denied. Does that occur because the terminated process is no longer available or does it occur because it was blocking a thread in app1 and it was unable to report the error until the thread was allowed to continue?

The code used to terminate app2 is

    private static void CloseSW(SldWorks swApp, Process sw_proces)
    {
        // Close with API call            
        if (Task.Run(() => { swApp.CloseAllDocuments(true); swApp.ExitApp(); }).Wait(TimeSpan.FromSeconds(20)))
            return;

        // Kill process if API call failed
        if (Task.Run(() => { SWHelper.CloseSW(sw_proces); }).Wait(TimeSpan.FromSeconds(20)))
            return;

        // Unable to close SolidWorks, ignore error and continue      
        // This will eventually cause SolidWorks to crash and the crash handler will take over
    }

This code should never take much more than 40 seconds to complete, but maybe the COM interop is causing some unexpected behaviour?

I am unable to reproduce this error on a development machine. What it the best way to trace the exact point of failure? It is possible that the failure is not in CloseSW but some point before this. Is there a better way to trace the error than to write each line to a log file?

It is also worth noting that this code works for 60 - 150 runs before it has any errors and both applications are closed between each run.

I have control of the remote environment so remote debugging is an option, but I've never set that up before.

1 Answer 1

1

Typically with COM interops causing issues is that IIS is having issues with the object using the current ISAPI.dll. Please verify that your permissions are configured within your assembly to work with your current version of IIS>

A few questions to help assist would be, which framework version are you using, which version of IIS and what is your Application Pool using for a framework.

HTH

Sign up to request clarification or add additional context in comments.

2 Comments

This is a console application running .NET Framework 4.5.2
If you are using msvsmon.exe to debug your server you may want to look at this url, msdn.microsoft.com/en-us/library/y7f5zaaa.aspx. The remote debugging should help you get a dump file to look at but I feel as if a race condition is happening in your code that may require some atomic operation to be created to fix the race.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.