Author Topic: .NET Code Suddenly Takes a Dive  (Read 12647 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
.NET Code Suddenly Takes a Dive
« on: March 11, 2016, 05:25:35 PM »
A project I'm involved with has been running really stable for several months but now suddenly it's faulty with an intermittent problem...and don't you love the sound of that. Anyway, the C# code takes input from a database, does some things for the sales and fabrication departments and then launches AutoCAD and a LISP program to create a drawing. It's been creating anywhere from 50 to 200 drawings each day. So far so good. This thing is totally automated so there's no need or allowance for human interaction.

What's happening now is that around 3-4 runs per day, AutoCAD stalls just before it starts the drawing process. In debugging I've checked. When I check the error messages I get this:

Code: [Select]
ERROR: System.Runtime.InteropServices.COMException (0x8001010A): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
   at AutoCAD.IAcadDocument.SendCommand(String Command)
   at BOM_CALCS.LaunchAutoCAD.StartAutoCAD() in C:\Engineering\Calculations\BOM\BOM_CALCS\LaunchAutoCAD.cs:line 55
   at BOM_CALCS.Program.Main(String[] args) in C:\Engineering\Calculations\BOM\BOM_CALCS\Program.cs:line 102
Unfortunately the 3-4 times per day has now grown to 10-12 times per day. There's not much in the way of help for this because it's intermittent. And the same code that runs perfect all other times hits this enough for it to be of concern.



MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: .NET Code Suddenly Takes a Dive
« Reply #1 on: March 11, 2016, 05:58:53 PM »
this message:

The message filter indicated that the application is busy

could be a clue that the application is getting smashed by more than one request at a time, this link may be of some help

https://msdn.microsoft.com/en-us/library/ms228772.aspx

hth
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #2 on: March 11, 2016, 08:59:23 PM »
Thanks, but I'm pretty sure that's not the issue. There are times I've seen this run three (3) runs at a time. It almost always runs one at a time about every 5-10 minutes. Sometimes it's heavier but usually it's quiet enough for it to not have simultaneous runs. And the times I see it fail is when it's running only one instance. Wish it were that easy. This is a hard one to crack.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2121
  • class keyThumper<T>:ILazy<T>
Re: .NET Code Suddenly Takes a Dive
« Reply #3 on: March 11, 2016, 11:04:07 PM »
< .. >

Code: [Select]
ERROR: System.Runtime.InteropServices.COMException (0x8001010A): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
   at AutoCAD.IAcadDocument.SendCommand(String Command)
   at BOM_CALCS.LaunchAutoCAD.StartAutoCAD() in
        C:\Engineering\Calculations\BOM\BOM_CALCS\LaunchAutoCAD.cs:line 55

   at BOM_CALCS.Program.Main(String[] args) in
        C:\Engineering\Calculations\BOM\BOM_CALCS\Program.cs:line 102

Hi Bill
I don't play with Com, but :
What is the client version
What is the development API version

What is the Command you are trying to send.
What is the code at line 55 and prior that is failing.

Did you develop this app on an earlier version of the client.

Is the App running on the same machine as the client.

Single User or multiple ?
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #4 on: March 13, 2016, 11:50:59 AM »
Thanks kdub. I will be able to reply with definite points tomorrow when I'm back in the office. The tricky thing about this is that it has seen days, weeks, on end when it works perfectly. A very experienced developer was hired recently and he introduced an RPC service into the mix. This is when I started noticing the problem. However, in his defense all I can say is it's an intermittent problem. That is out of 100 runs each day only about 10 of them will have trouble. And he has extensive experience in development, I mean this guy practically invented OOP and he thinks the problem is a COM object being left un-closed but so far I'm not seeing that. I will be working on this with him more starting tomorrow morning.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: .NET Code Suddenly Takes a Dive
« Reply #5 on: March 13, 2016, 07:56:02 PM »
... he thinks the problem is a COM object being left un-closed.....

would be my first guess too, but, I haven't invented anything

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2121
  • class keyThumper<T>:ILazy<T>
Re: .NET Code Suddenly Takes a Dive
« Reply #6 on: March 13, 2016, 10:41:51 PM »


Quote
< .. >
The tricky thing about this is that it has seen days, weeks, on end when it works perfectly. A very experienced developer was hired recently and he introduced an RPC service into the mix. This is when I started noticing the problem.
< .. >

This is one of the issues with peer to peer forums.
The critical information doesn't get offered up in the first post.

My questions shouldn't need to be asked.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #7 on: March 16, 2016, 11:33:07 AM »
Thanks again for everyone's patience. Let me see now if I can spell out the problem because this has become a major bug that I must resolve.

This is a completely automated project, no users are allowed to interface with it. The only exception being me the main developer and I only mess with it when it stalls. Basically Apache+php (XAMPP) listens for requests from the network. Upon receiving one the main .exe of my project is launched from a php program. All that is working well. Eventually, the call is made to AutoCAD to produce a drawing.  The code which I use to launch AutoCAD is thus:
Code: [Select]
using System;
using AutoCAD;

namespace AHD_BOM_CALCS
{
    class LaunchAutoCAD
    {
        private static IAcadApplication vAcadApp = null;
        private static IAcadDocument vAcadDoc = null;

        // CHANGE THIS TO AutoCAD.Application.20 FOR ACAD 2015/16
        private static string vAcadID = "AutoCAD.Application.20";

        private static string LispPath = @"C:/Engineering/04VLISP/ANGLE/Bomber/";
        private static string DwgPath = @"C:\Engineering\09Automated Drawings\";
       
        public static void StartAutoCAD()
        {
            try
            {
                // Check for instance of AutoCAD
                vAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(vAcadID);
            }
            catch (Exception) // If none found start a new instance of AutoCAD
            {
                System.Type AcadProg = System.Type.GetTypeFromProgID(vAcadID);
                vAcadApp = (IAcadApplication)System.Activator.CreateInstance(AcadProg);
            }

            string titleblock = "Template1(Automated).dwg";

            if (vAcadApp != null)
            {
                vAcadApp.Visible = true;
                vAcadDoc = vAcadApp.Documents.Open(DwgPath + titleblock, true);
                string LispName = "Bomber.lsp";
                vAcadDoc.SendCommand("(load \"" + LispPath + LispName + "\" \"The load failed\") ");
                vAcadDoc.SendCommand(LISPVariables.PrepareAcadCmd() + " ");
                vAcadDoc.SendCommand("(setvar \"osmode\" 703) ");
                vAcadDoc.SendCommand("(setvar \"cmdecho\" 1) ");
                vAcadDoc.SendCommand("(setvar \"pickbox\" 5) ");
           
              vAcadDoc.SendCommand("(setq svPath \"C:/0/Misc/BomberDevDwgs/\") ");
              vAcadDoc.SendCommand("(setq *erp 1) ");
              vAcadDoc.SendCommand("DrawitNow ");
            }
            else
            {
                Console.WriteLine("ERROR: The drawing file is missing.");
                Console.ReadKey();
            }
        }
    }
}

Prior to running this class, the C# project does a bunch of calculations and writes those results to an Oracle database. All of that part is running fine, never an issue. It's only when the LaunchAutoCAD class gets to the SendCommand lines where things go south. And it never seems to fail at the same line. Sometimes none of the commands go and sometimes 2 or 3 of them go but then it stalls and never gets the last command which is "Drawit" which starts the LISP code. The drawing is produced and saved to the server. It runs all day and night long listening for requests. Out of over 100 runs each day about 5-10 times it stalls. I have checked the workstation where this project runs and there does not seem to be anything like a stuck acad.exe process in the Task Manager or anything else. I have cold booted it to see if that will clear the cobwebs but that did not help. As the old saying goes, I'm ready to urinate on a spark plug if that will work.

ChrisCarlson

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #8 on: March 16, 2016, 12:07:28 PM »
Since it's tripping up at the SendCommand() area, you can try removing some of the commands. Do these three really need to be set within the C# section of code? It would be quite easy and clean to run them in the beginning of your lisp routine.

Code - C#: [Select]
  1. vAcadDoc.SendCommand("(setvar \"osmode\" 703) ");
  2. vAcadDoc.SendCommand("(setvar \"cmdecho\" 1) ");
  3. vAcadDoc.SendCommand("(setvar \"pickbox\" 5) ");

Code - Auto/Visual Lisp: [Select]
  1. (if (not (= (getvar "osmode") 703)) (setvar "osmode" 703))
  2. (if (not (= (getvar "cmdecho") 1)) (setvar "cmdecho" 1))
  3. (if (not (= (getvar "pickbox") 5)) (setvar "pickbox" 5))
 


Jeff H

  • Needs a day job
  • Posts: 6144

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: .NET Code Suddenly Takes a Dive
« Reply #10 on: March 16, 2016, 12:53:21 PM »
Why using sendCommand since you can call or change the system variable via the application?

e.g;

Code - C#: [Select]
  1. Application.SetSystemVariable("OSMODE", 0);
  2.  

ChrisCarlson

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #11 on: March 16, 2016, 01:03:01 PM »
Why using sendCommand since you can call or change the system variable via the application?

e.g;

Code - C#: [Select]
  1. Application.SetSystemVariable("OSMODE", 0);
  2.  

Don't think that would work from outside of an AutoCAD executed program.

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: .NET Code Suddenly Takes a Dive
« Reply #12 on: March 16, 2016, 01:08:38 PM »
Why using sendCommand since you can call or change the system variable via the application?

e.g;

Code - C#: [Select]
  1. Application.SetSystemVariable("OSMODE", 0);
  2.  

Don't think that would work from outside of an AutoCAD executed program.
Opps, Sorry I did not notice that.
Thanks Chris

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #13 on: March 16, 2016, 01:35:03 PM »
Since it's tripping up at the SendCommand() area, you can try removing some of the commands. Do these three really need to be set within the C# section of code? It would be quite easy and clean to run them in the beginning of your lisp routine.

Code - C#: [Select]
  1. vAcadDoc.SendCommand("(setvar \"osmode\" 703) ");
  2. vAcadDoc.SendCommand("(setvar \"cmdecho\" 1) ");
  3. vAcadDoc.SendCommand("(setvar \"pickbox\" 5) ");

Code - Auto/Visual Lisp: [Select]
  1. (if (not (= (getvar "osmode") 703)) (setvar "osmode" 703))
  2. (if (not (= (getvar "cmdecho") 1)) (setvar "cmdecho" 1))
  3. (if (not (= (getvar "pickbox") 5)) (setvar "pickbox" 5))


Thanks Chris, that is one of the ideas I've been toying with but with the randomness of where it fails I don't know it that's the ticket. However, I am cold booting the machine right now and will start trying out some more of these suggestions. You guys are the best.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: .NET Code Suddenly Takes a Dive
« Reply #14 on: March 16, 2016, 01:47:16 PM »
I'm wondering if there is potentially a regen involved in the cycle, as the application is made visible and a drawing is opened.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}