Menu

#17 Command line build sometimes hangs forever

v1.7
closed
nobody
None
5
2014-03-16
2013-06-15
stinos
No

I'm building a chm and pdf file using the commandline with /q /g /y switches. The command is invoked from TeamCity if that matters. Occasionaly the chmprocessor process just seems to hang and doesn't do anything anymore, the only thing I can do then is kill the process. Do you have any idea what could cause this? I cannot reliably reproduce the issue, just that 1 out of 20 builds or so it happens.

Discussion

  • Antonio Fco. Bennasar Obrador

    There is two places where I saw hangs: HTML files load with mshtml and PDF generation (with pdfcreator, the MS word PDF generation works perfectly).

    On 1.7 version, I don't longer use mshtml, so this should be fixed. For the second, if you can, install MS office and use that pdf generation.

     
  • stinos

    stinos - 2013-09-04

    I am using MS pdf generation - this was quite critical for us so I downloaded the code and debugged it. The hanging occurred in MSWord.cs: in SaveWord() the code would wait infinitely on while( IsOpen( wordFileSrc ) ). Not sure what the cause was (I think the way isOpen works is wrong) but after removing it everything seemed ok.

     
  • Antonio Fco. Bennasar Obrador

    Changed the code on version 1.7 to check a timeout waiting to close the document ( while (IsOpen(wordFileSrc) && currentWaitTime < MAXWAITOPENDOCUMENT) ), up to 20 seconds.

    This is a ugly patch, but i don't have time for more. Hope it will fix it.

     
  • Markus KARG

    Markus KARG - 2014-01-21

    Using 1.6.3 of chmProcessor manually at the command line (Win 7 Pro SP1 64 Bit) I can confirm that 1.6.3 actually is waiting for a final [ENTER]. It hangs before you press that key, and CMD prompts once you pressed it.

    chmProcessor.exe MyDoc.doc /g /q /y /e

     
  • Jozsef Bekes

    Jozsef Bekes - 2014-01-27

    Hi

    I have fixed this in code by doing this in the app:

    FreeConsole();
    System.Windows.Forms.SendKeys.SendWait("{ENTER}");

    Here is the pinvoke for FreeConsole():

    [DllImport("kernel32.dll")]
    public static extern bool FreeConsole();

    Took the idea from here:
    http://stackoverflow.com/a/12420489

    Please note that if you call Console.Write() after FreeConsole that is a crash so be careful if you make this change to the project.

    Thank you,
    Jozsef

     
  • Jozsef Bekes

    Jozsef Bekes - 2014-01-27

    BTW the code I wrote above still has issues e.g. you cannot redirect the stdout to a file. I have a project that had this problem and in the end what I do is I specified the app as a console app, then if it is started in gui mode I call freeconsole otherwise not. This unfortunately means that the console can be visible for a flash when started in GUI mode but all the console stuff works well which was my preference in that project. Maybe providing a logfile option could be considered as well?

     
  • stinos

    stinos - 2014-01-27

    Kinda forgot about this issue; was using pdf generation using Word, never saw a console popping up so I'm not sure if your fix would work for me. Also didn't try the patch with the timeout as it was quite urgent. Instead I fixed it by removing the waits in a couple of places and have no problems whatsoever.

    In MSWord.Dispose() I removed the call to CloseAllDocuments as that sometimes generated an exception, resulting in the rest of the code which actually closes Word not being called. Furtermore in that code I removed the everything under 'Wait until Word shuts down'.

    In MSWord.SaveWord() I just removed everything under 'Be sure the document is closed' as that casued most of the problems.

     
  • Jozsef Bekes

    Jozsef Bekes - 2014-01-28

    I am not using word (only have libreoffice on my PC). The problem in my case comes from the console attach as the stackoverflow article also explains. On my PC (win7 64 bit) if I attach to the console and call console.writeline even just once the problem occurs, do not get the prompt back after execution (the chmProcessor process is finished by this time) until I push enter.

    I executed this:
    chmProcessor /g /y /q myapphelp.WHC

    I am not saying that pushing enter is a good robust solution but for now it works for me. I think the proper solution is the 2 executable files thing (well it is a proper workaround for a nasty problem in windows).

     
  • Jozsef Bekes

    Jozsef Bekes - 2014-01-28

    Attaching my whc file.

     
  • Jozsef Bekes

    Jozsef Bekes - 2014-01-28

    Unfortunately when the code "pushes" the enter button, if another app has the focus the other app will receive the message, so in the end I changed the project to console and destroy the console window if in GUI mode.

    class CommandLineMode

        [DllImport("kernel32.dll")]
        static extern IntPtr GetConsoleWindow();
    
        [DllImport("user32.dll")]
        static extern bool DestroyWindow(IntPtr hWnd);
    
        [DllImport("kernel32.dll")]
        static extern bool FreeConsole();
    

    public void Run()
    {
    if (!outputQuiet)
    {
    FreeConsole();
    DestroyWindow(GetConsoleWindow());
    }
    ...
    }

    I think this does not work as expected if you run the app from visual studio but behaves well when you run it from windows explorer or console etc. This solution is ideal for console run, the GUI execution has the problem that the console window appears for a very short time during startup. Not that it matters for me, I just want to use the app on the build pc, but I like solutions to be reasonably nice :-)

     
  • Antonio Fco. Bennasar Obrador

    1) Joszef: Agree with the two exes for the same thing. Winrar does (winrar.exe / rar.exe, God bless winrar programmers, some day I'll pay the license). When you create a "Windows application", the console integration is not easy (Redirection not working, prompt not working well, etc). Hope have time for it.

    2) stinos: Ill put a checkbox on the configuration window with an option to disable the Word files wait to close (under CloseAllDocuments and 'Wait until Word shuts down') . I still not seeing any wait with this, but ill put it to disable the Word files close waits.

    3) Markus:

    "Using 1.6.3 of chmProcessor manually at the command line (Win 7 Pro SP1 64 Bit) I can confirm that 1.6.3 actually is waiting for a final [ENTER]. It hangs before you press that key, and CMD prompts once you pressed it.

    chmProcessor.exe MyDoc.doc /g /q /y /e"

    Mmm. On my tests, until you dont press Enter, the "C:...>" prompt don't appears BUT, the console is working, and accepting petitions. So if you chain more than one call on a BAT file to chmProcessor, all will be called, so there is no need to any "Enter" key press. I do it usually.

    4) All: I still supporting the project, but I have not so much time for it. Anybody interested on SVN access? I warn you the code is pretty crappy (it was the first thing I did to learn C#)

     
  • stinos

    stinos - 2014-03-10

    2) seems nice - though for now I'll probably just continue using the working version I have

    4) sorry, I'd wish, but not enough time to do something meaningful atm

     
  • Antonio Fco. Bennasar Obrador

    Added a new console exe for console generation (chmprocessorcmd.exe). It will be in v 1.7.1

     
  • Antonio Fco. Bennasar Obrador

    • status: open --> closed
    • Group: v1.0 (example) --> v1.7
     

Log in to post a comment.