.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AcCoreConsole hang at Process

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
wesbird
1044 Views, 9 Replies

AcCoreConsole hang at Process

Hi,

I created a LispFunction in C# to print mutiple layout out as PDF. it works fine in AutoCAD.
then I create a script (.scr) to run this LispFunction, a bat file to call AcCoreConsole and this script file, and run it from DOS command line, it also works just fine 
after that, I create a C# exe, use Process to call AcCoreConsole, use the same parameter in my bat file in Process, it hang at 3rd layout, right before the line of code below:

 

LayoutManager.Current.CurrentLayout = layoutToPrint;

first 2 layout print out as PDF successfully. 

 

Anybody had the same problem before?


Thank you
Wes

AutoCAD 2016, .Net 4.5.2

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
9 REPLIES 9
Message 2 of 10
FRFR1426
in reply to: wesbird

Exception message?

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 10
wesbird
in reply to: FRFR1426

Too bad, there is no exception message. It simply timeout. 

 

Thank you, FRFR1426

Wes

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 4 of 10
BKSpurgeon
in reply to: wesbird

Hi

 

You say that it times out when it tries to print the third pdf.

 

A couple of things to try:

 

  1. Get rid of the other two files. Run the script file (through your c# exe)  on just the file where it was hanging - just one file.  Does it successfully print?
  2. copy one of the files three times (not the one that hangs) - and then run it - do all three files print?
    1. test1.dwg
    2. test2.dwg
    3. test3.dwg
  3. Consider the following line of code:
LayoutManager.Current.CurrentLayout = layoutToPrint;

 

how is the layoutToPrint value derived?

 

 

 

hope this helps.

 

rgds

 

 

BK

Message 5 of 10
FRFR1426
in reply to: wesbird

BACKGROUNDPLOT at 0?

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 6 of 10
wesbird
in reply to: BKSpurgeon

Hi, BKSpurgeon

 

Sorry I didnot make it very in my first post. 

I did not have problem to print multiple DWG file, I have problem to print multiple layout of one DWG file. 

I tried another DWG file, it hang at 4th layout. 

 

layoutToPrint is the name of layout to print out. 

 

 

Thank you

Wes

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 7 of 10
wesbird
in reply to: FRFR1426

Hi, FRFR1426

 

I set BACKGROUNDPLOT to 0 in my code. 

 

Here is the code I used to run AcCoreConsole, which I learned here or swamp. might be the trouble come from?

 

        public void Run_Process(string FileName, ACCResult ccr)
        {

            using (Process process = new Process())
            {
                process.StartInfo = CreateProcessStartInfo(FileName);

                process.Start();

                if (!process.WaitForExit(_ProcessInfo.MaxTime))
                {
                    ccr.Status = ACCStatusCode.Timeout;
                    process.CloseMainWindow();
                    if (!process.WaitForExit(2000))
                    {
                        process.Kill();
                    }
                }
                else
                {
                    string output = process.StandardOutput.ReadToEnd();
                    output = output.Replace("\0", "").Replace("\r\n", "").Replace("\b", "");

                    string err = process.StandardError.ReadToEnd();
                    if (!string.IsNullOrEmpty(err))
                        output += Environment.NewLine + BPLog.ERROR_MARK + err;

                    ccr.OutPut = output;
                }
            }
        }
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 8 of 10
FRFR1426
in reply to: wesbird

What's _ProcessInfo.MaxTime?

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 9 of 10
wesbird
in reply to: FRFR1426

Thank, FRFR1426

 

_ProcessInfo.MaxTime was 10,000, then I change to 100,000. neither works. 

 

later yesterday, I change the code from 

if (!process.WaitForExit(_ProcessInfo.MaxTime))
{
  ccr.Status = ACCStatusCode.Timeout;
  process.CloseMainWindow();
  if (!process.WaitForExit(2000))
  {
    process.Kill();
  }
}

 

to

process.WaitForExit(_ProcessInfo.MaxTime);

then it works. 

I'm  not good at this one. good it works. 

 

 

Thanks

Wes

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 10 of 10
FRFR1426
in reply to: wesbird

It seems that the process you're starting is returning before the processing of the PDF is done. You should check what's happening with a tool like Process Explorer.

 

Anyway, a timeout of 10 000 ms (10 secondes) was definitely too short for this kind of operation.

 

Calling WaitForExit with a timeout has no sense if you're not checking the return value. If your calling program does not have to wait, just don't use WaitForExit.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report