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

0 Members and 1 Guest are viewing this topic.

n.yuan

  • Bull Frog
  • Posts: 348
Re: .NET Code Suddenly Takes a Dive
« Reply #15 on: March 16, 2016, 01:49:23 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.

Well, the OP's code has already obtained the AcadApplication object, it can certainly be done (and should be done):

vAcadApp.SetSystemVariable(...)

instead of SendCommand(), which is likely the cause of his problem.

n.yuan

  • Bull Frog
  • Posts: 348
Re: .NET Code Suddenly Takes a Dive
« Reply #16 on: March 16, 2016, 02:05:09 PM »
Using full desktop AutoCAD as a non-user-interactive server app is problematic, to say the least. Especially your code try to use the same instance of AutoCAD session (the code first tries to find existing AutoCAd session, and only start a new session of no existing one is obtained), which is particular bad practice when using AutoCAD as "server" (plus, multiple SendCommand() calls that could be executed out of sync makes thing even worse). Even you can claim it had worked for quite a while, it was mostly out of good luck (low work load), IMO.

If you have to use AutoCAD as server, it would be better to start a new AutoCAD session, build one drawing and then close the AutoCAD session. Just imagine, when drawing building is in progress, and since the process need to get data from somewhere (Oracle DB, as you mentioned) outside the process, and you never know what could happen and the process has to wait the data come back. So, the drawing building process could be long or short. If then a nother request comes in and you code luckily find the existing AutoCAD session and tries to hold it for new request while the existing AutoCAd session is still working on previous request... Your app now may be in a "dead lock" state.

Depending on your workload, running multiple AutoCAD session in the same computer may also be problematic, of course, because AutoCAd desktop app is such a "resouces" hangry beast.

You should consider to use AutoCAD console for this type of work instead of full AutoCAD.

ChrisCarlson

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #17 on: March 16, 2016, 02:47:34 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.

Well, the OP's code has already obtained the AcadApplication object, it can certainly be done (and should be done):

vAcadApp.SetSystemVariable(...)

instead of SendCommand(), which is likely the cause of his problem.

Interesting, stepping back and coming back that makes sense. So based on dropping the SendCommand() is it a moot point between vAcadApp.SetSystemVariable within C# and (setvar ...) within LISP?

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #18 on: March 16, 2016, 03:13:35 PM »
https://msdn.microsoft.com/en-us/library/ms228772.aspx
By George, I think you've got something there. However, after the reboot, the project has just made 15 successful consecutive runs. Turns out the tech who told me he rebooted it last week was confusing it with another machine. So to avoid confusion I went into the cold room and rebooted it myself. Now, I'm not saying that a reboot fixed it but it's running better than it was. And looking into that article you referenced our .NET guru and myself are going to look into that further. In any case, I think now the overseers are a little more understanding that it's not the C# code itself, and it's especially not the LISP code. Rather it does appear to be a conflict between Visual Studio and a multi-threaded app like AutoCAD...

   translation =  it's all Bill Gate's and Steve Balmer's fault .... wink, wink, nudge, nudge!

However, there's no proof in the pudding yet, just some reassurance that debugging the code it not the answer. Another tech here just told me that he actually has a script to reboot Windows 7 machines for this very reason. They run automated tasks and similar problems occur unless they reboot it every night.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: .NET Code Suddenly Takes a Dive
« Reply #19 on: March 16, 2016, 03:23:44 PM »
AutoCAD is NOT multi-threaded (in fact, you can't do that with AutoCAD customization at all) except for a couple of parts which don't/shouldn't have any relevance here.
If you are going to fly by the seat of your pants, expect friction burns.

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

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #20 on: March 16, 2016, 03:26:59 PM »
Using full desktop AutoCAD as a non-user-interactive server app is problematic, to say the least. Especially your code try to use the same instance of AutoCAD session (the code first tries to find existing AutoCAd session, and only start a new session of no existing one is obtained), which is particular bad practice when using AutoCAD as "server" (plus, multiple SendCommand() calls that could be executed out of sync makes thing even worse). Even you can claim it had worked for quite a while, it was mostly out of good luck (low work load), IMO.

If you have to use AutoCAD as server, it would be better to start a new AutoCAD session, build one drawing and then close the AutoCAD session. Just imagine, when drawing building is in progress, and since the process need to get data from somewhere (Oracle DB, as you mentioned) outside the process, and you never know what could happen and the process has to wait the data come back. So, the drawing building process could be long or short. If then a nother request comes in and you code luckily find the existing AutoCAD session and tries to hold it for new request while the existing AutoCAd session is still working on previous request... Your app now may be in a "dead lock" state.

Depending on your workload, running multiple AutoCAD session in the same computer may also be problematic, of course, because AutoCAd desktop app is such a "resouces" hangry beast.

You should consider to use AutoCAD console for this type of work instead of full AutoCAD.
Yes, I agree with all that you said. However, the nature of this project means that several requests may hit simultaneously. Let me elaborate on that if I may. In this setup we use a Load Balancing server which sends requests to one of two identical Windows 7 machines running Apache+php and AutoCAD 2016 Mechanical. AutoCAD is loaded and sitting there with no drawing open all the time. Presently, and due to all the code changes happening at this stage, we let one of them sleep and the other works all day but eventually we will turn both of them on and it can handle the load, even with 200-300 requests per 8 hour shift. I have seen just one of these boxes handle up to three instances successfully without a problem. But when a 4th one hits, it's a no-go and AutoCAD just chokes on it all. And it's not foreseen that even under the heaviest loads that we would put on it, two machines will be more than adequate.

I tried it with your suggestion of launching AutoCAD on each run long ago but since AutoCAD can take up to 3 minutes to load, that just wasn't an option. So leaving it open with no drawing open works fine. There are times when a drawing file is open but again, these computers are not accessible at their consoles. I've also witnessed times when one of the hung drawings is sitting there on the monitor and another run comes in and completes just fine.

There are of course lots of options we will look at over the next few weeks. There is even talk of getting rid of AutoCAD all together and use some other kind of rendering engine, but I've warned them that how do you send a client an AutoCAD file if there is no AutoCAD to produce it. The techs counter with anything running on Microsoft is too error prone and we have to eliminate it if possible. They get no argument from me on that point.

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #21 on: March 16, 2016, 03:50:34 PM »
AutoCAD is NOT multi-threaded (in fact, you can't do that with AutoCAD customization at all) except for a couple of parts which don't/shouldn't have any relevance here.
Aha, I was not aware of that. I thought it was. Shows how much I know.
https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Support-for-multi-core-processors-with-AutoCAD.html
I used AutoCAD for loads of renderings a few years ago and would watch the renderings progress with each one of the little squares which indicated that one of the cores was being used. When I saw 12 little boxes prepare the rendering I assumed (wrongly I might add) that AutoCAD was an entirely multi-threaded app.

In any case, after the reboot, the box has now made 32 runs completely without incident. That's much better than it was doing this morning and yesterday. So until we figure out some other ideas, I'm just going to reboot this thing each evening.

ChrisCarlson

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #22 on: March 16, 2016, 03:54:46 PM »
You can bypass AutoCAD loading, kind of

http://www.techsoft3d.com/products/autodesk-platforms/realdwg/

For the price it's pretty haphazardly put together but an option.

Bill Tillman

  • Guest
Re: .NET Code Suddenly Takes a Dive
« Reply #23 on: March 16, 2016, 04:28:53 PM »
Thanks again everyone. After rebooting the machine has now run 42 instances, or about a 1/2 day's normal usage without errors. Long ago when I worked in IT the users would always complain that my resolution to almost everything was just reboot. Hey it works doesn't it. I'm not saying this is the final and ultimate resolution but it's working for now and allowing me to get on with other tasks. And I can finally tell some skeptics around here: "Left open Com objects? I ain't got no left open Com Objects. I don't need no stinking left open Com Objects!"
« Last Edit: March 16, 2016, 04:32:59 PM by Bill Tillman »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: .NET Code Suddenly Takes a Dive
« Reply #24 on: March 17, 2016, 08:31:15 PM »
There is even talk of getting rid of AutoCAD all together and use some other kind of rendering engine, but I've warned them that how do you send a client an AutoCAD file if there is no AutoCAD to produce it.

Maybe also look at https://developer.autodesk.com/api/autocadio/

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: .NET Code Suddenly Takes a Dive
« Reply #25 on: March 18, 2016, 10:51:25 AM »
Wow, you all need something like teigha, or realdwg

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: .NET Code Suddenly Takes a Dive
« Reply #26 on: March 20, 2016, 06:23:15 PM »
If you wanted to scale up you could just rent extra copies of AutoCAD by the month and run them on spare computers.

Teigha .NET Classic is definitely an option, it's free for in-house use (apart from the annual membership) for the first 2 years, then is gets more expensive: https://www.opendesign.com/Commercial

You can bypass AutoCAD loading, kind of
http://www.techsoft3d.com/products/autodesk-platforms/realdwg/
For the price it's pretty haphazardly put together but an option.
Confirmed. If you think the Docs on AutoCAD .NET are ... well, you know ... you should see the docs for their lesser-used platform. Building the installer is a nightmare, there's no pre-fab solution as such. I hope you know and love Wix. I assume building an installer for Teigha stuff is just as tricky.

AutoCAD is NOT multi-threaded (in fact, you can't do that with AutoCAD customization at all) except for a couple of parts which don't/shouldn't have any relevance here.
Aha, I was not aware of that. I thought it was. Shows how much I know.
https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Support-for-multi-core-processors-with-AutoCAD.html
I used AutoCAD for loads of renderings a few years ago and would watch the renderings progress with each one of the little squares which indicated that one of the cores was being used. When I saw 12 little boxes prepare the rendering I assumed (wrongly I might add) that AutoCAD was an entirely multi-threaded app.
...
I believe parts of the rendering engines are multi-threaded but the Database engine definitely isn't. You can run background threads for things unrelated to Database access but everything for Database access must run on the UI thread.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: .NET Code Suddenly Takes a Dive
« Reply #27 on: March 20, 2016, 06:49:01 PM »
If you wanted to scale up you could just rent extra copies of AutoCAD by the month and run them on spare computers.

The cost of using something like Teigha isn’t per-seat.
It would probably be an order of magnitude faster, and much cleaner option than using send command

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: .NET Code Suddenly Takes a Dive
« Reply #28 on: March 20, 2016, 11:22:32 PM »
If you wanted to scale up you could just rent extra copies of AutoCAD by the month and run them on spare computers.

The cost of using something like Teigha isn’t per-seat.
It would probably be an order of magnitude faster, and much cleaner option than using send command
Agreed. My suggestion was a way to scale with no more development effort. Doing it properly would definitely work better, as you would expect.