While loop takes CPU resources

Discussion in 'AutoCAD' started by Tim Skene, Jan 6, 2005.

  1. Tim Skene

    Tim Skene Guest

    I'm running another application from lisp and need to wait for it to create
    a registry value, then do something according to the value.
    Reading the value in a WHILE loop takes much CPU resources (99% in
    task manager) and if you switch to another app and back to ACAD the screen
    seems to freeze and things really slow down.

    To see what I mean, run this loop on the command line and try switching to
    another app and back.

    (while (null test) (command))

    Is there any way to loop without taking so much resources? I could pause
    with a dialog or alert button to click, but that adds an unnecessary
    and awkward looking step.

    Thanks.


    Tim Skene
     
    Tim Skene, Jan 6, 2005
    #1
  2. Try:

    (while <condition>
    (command "._DELAY" 1000) ; change millisecs to suit
    )
     
    Tony Tanzillo, Jan 6, 2005
    #2
  3. Tim Skene

    Tim Skene Guest

    Try:
    Makes no difference. Whether I put a long, short or no delay in the loop, it
    seems to be the overhead of the while loop that causes the problem.
     
    Tim Skene, Jan 6, 2005
    #3
  4. Tim Skene

    Alaspher Guest

    may be anything like:
    Code:
    (vlax-invoke-method
    (vlax-get-or-create-object "wscript.shell")
    "run"
    (strcat "youapplication.exe\ " "externalfile.ext")
    1
    :vlax-true
    )
    AutoCAD will wait while "youapplication" is active.

    best regards!
     
    Alaspher, Jan 6, 2005
    #4
  5. The point to the delay is to avoid doing what you're
    doing in the while loop as frequently as its happening.

    If you initiate an external process synchronously (e.g.,
    where your LISP code did not continue until after the
    external process is finished), AutoCAD would not
    respond until your LISP code has resumed and does
    something that causes AutoCAD to begin polling for
    input, anyways.

    So, the problem is not that AutoCAD becomes
    bogged down while waiting for the external process,
    the problem is that your are running the extarnal
    process asynchronuosly (e.g., where your LISP code
    does not wait for it to complete), to begin with.

    I think you'll find that even if you run the external
    process synchronously (e.g., your LISP code would
    not continue until the external process completes,
    which can be done using a DOSLIB function, I think),
    you will still see this happen if the external process
    takes any significant time to complete.
     
    Tony Tanzillo, Jan 6, 2005
    #5
  6. Nice functions Tony. Is there a way to keep ACAD from grabbing focus every
    second or so? It even grabs focus when (vla-put-windowstate
    (vlax-get-acad-object) 2).

    Regards,
    Eric S

     
    Eric Schneider, Jan 6, 2005
    #6
  7. Eric - Not sure what you mean by 'grabbing focus'.

    Is AutoCAD in the foreground, or is it bringing itself
    into the foreground and taking focus from another app?

    If so, what app?

    Doesn't happen here using the sample test function I
    posted (which does nothing in the (while) loop).

    Perhaps there's something in your loop that's
    doing it?



     
    Tony Tanzillo, Jan 6, 2005
    #7
  8. I'm not doing anything within the (slightly modified, see below) C:TEST
    function either, just trying it out before I implement it. While in the
    while loop (while the while, heh heh), if I switch focus to any other app,
    like notepad, Outlook or Explorer, I don't have enough time to do anything
    before it looses focus to ACAD.

    Create a file named C:\b.txt, start the C:TEST function and try to rename it
    to C:\a.txt.

    (defun C:TEST (/ acad ws)
    (setq acad (vlax-get-acad-object))

    ;; This will prevent the user from
    ;; switching to a different document.
    ;; (improper use of this function can
    ;; be dangerous):

    (DisableDocumentActivation)
    (setq ws (vla-get-windowstate acad))
    (vla-put-windowstate acad 2)

    ;; This code is wrapped in an exception handler
    ;; to ensure the call to EnableDocumentActivation
    ;; that follows it, is reached. If it is not, there will
    ;; be problems:

    (vl-catch-all-apply
    '(lambda ()
    (while (not (findfile "C:/a.txt"));give it something to test

    ;; Calling this function forces AutoCAD
    ;; to process its message queue:

    (DoEvents)

    ;; Do whatever you need here
    )
    )
    )

    (vla-put-windowstate acad ws)
    (EnableDocumentActivation) ;; Make sure you do this!!!

    )
     
    Eric Schneider, Jan 6, 2005
    #8
  9. Eric - Doesn't happen here (WinXP SP2).

    Per chance, are you using some bozo (e.g. Win9x)
    operating system?
     
    Tony Tanzillo, Jan 6, 2005
    #9
  10. W2kpro with all the latest, ACAD2005 with all the latest.
     
    Eric Schneider, Jan 6, 2005
    #10
  11. Is there any other applications open? If so what are they?
     
    Tony Tanzillo, Jan 6, 2005
    #11
  12. Command: (dos_processes)
    ("smss.exe" "winlogon.exe" "services.exe" "lsass.exe" "svchost.exe"
    "spoolsv.exe" "msdtc.exe" "ActionAgent.exe" "DellDmi.exe" "EventAgt.exe"
    "DLT.exe" "svchost.exe" "Iap.exe" "mdm.exe" "nvsvc32.exe" "regsvc.exe"
    "MSTask.exe" "Win32sl.exe" "WinMgmt.exe" "svchost.exe" "inetinfo.exe"
    "svchost.exe" "Explorer.EXE" "jusched.exe" "PwsTray.exe" "TeaTimer.exe"
    "ctfmon.exe" "Printkey2000.exe" "OUTLOOK.EXE" "msimn.exe" "POINT32.EXE"
    "acad.exe" "AdskCleanup.0001" "AdskScSrv.exe" "WSCommCntr1.exe"
    "wisptis.exe"
    "pageant.exe" "putty.exe" "putty.exe" "winscp368.exe" "AcroTray.exe"
    "putty.exe" "IEXPLORE.EXE" "IEXPLORE.EXE" "notepad.exe" "IEXPLORE.EXE")
     
    Eric Schneider, Jan 6, 2005
    #12
  13. Sorry, no clue about why that's happening.

    Perhaps someone else can try it, and see if
    they get the same thing. I can't reproduce
    it on WinXP with A2K5.
     
    Tony Tanzillo, Jan 6, 2005
    #13
  14. It's quite annoying. I don't think it's your code. AutoCAD gains focus
    even when doing an autosave when I have another app in the foreground.

    Regards,
    Eric S
     
    Eric Schneider, Jan 6, 2005
    #14
  15. Tim Skene

    Tim Skene Guest

    Thanks for the replies everyone. I will check out the options, incl. Tony's
    arx file.

    I had thought of running a VBA app from the lisp to do what I need and then
    return to lisp. The principle seems to work so far.
     
    Tim Skene, Jan 6, 2005
    #15
  16. Tim Skene

    Jim Claypool Guest

    I tried it and I can go do anything I want.
    Map 2005 3D WinXP-Home Sp2
     
    Jim Claypool, Jan 6, 2005
    #16
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.