accoreconsole.exe freezes after series of transactions

35 Views Asked by At

In the AutoCAD plugin project I have been working for a while, we developed an API fo unit testing where we utilize XUnit and System.Diagnostics.Process class to launch accoreconsole with a test command that usually looks like this:

[Test, CommandMethod("LabelOverlapTest")]
public static void LabelOverlapTest()
{
    TestShell(() =>
    {
        // test code
    });
}

protected static void TestShell(Test test, Shell shell = Shell.AcCoreConsole, params string[] commands)
    {
        if (AutoCADLauncher.IsInsideAutoCAD())
        {
            try
            {
                test.Invoke();
            }
            catch (System.Exception e)
            {
                //Trace.WriteLine($"Exception: \"{e.Message}\"\n");
                // there is no other way to print message to AutoCAD console and exit with non-zero code
                var doc = Application.DocumentManager.MdiActiveDocument;
                doc.Editor.WriteMessage($"Exception: \"{e.Message}\"\n");
                // terminating current process
                Process.GetCurrentProcess().Kill();
            }

            if (shell == Shell.AutoCADgui)
            {
                Application.Idle += (_, _) =>
                {
                    foreach (Document doc in Application.DocumentManager) doc.CloseAndDiscard();

                    Application.Quit();
                };
            }
            return;
        }

        var launcher = new AutoCADLauncher(TestContext.CurrentContext.Test.Name, shell, commands);
        launcher.Launch();
        launcher.PrintAutoCADOutput();

        Assert.That(launcher.ExitCode, Is.EqualTo(0));
    }

This is how it works:

  1. The test function is created with CommandMethod() attribute;
  2. When test is launched, an AutoCAD script is created with the test command in it;
  3. AcCoreConsole is launched as external process using System.Diagnostics.Process;
  4. The program waits until console finishes its work (Process.WaitForExit());

The problem I have been facing for a while is: If accoreconsole is launched without a window and with redirected output, there is a fixed number of transactions that can be made before the process freezes. And this restricting exists even if no changes were made during a transaction. It does not happen neither with AutoCAD app nor with AcCoreConsole if launched with window and without redirectiong output. If I add command "_quit" to the end of a script, it does not help.

I tried to reinstall AutoCAD several times but problem still persisted.

Edit: I added some changes to the project (some additional curves added during specific command, reduced overall transaction number), and transaction limit for some reason was reduced by more than 10.

Please help. Thanks in advance.

0

There are 0 best solutions below