wxProcess running

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Ollow_AM
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Feb 26, 2010 10:22 am

wxProcess running

Post by Ollow_AM » Mon Nov 28, 2011 3:33 pm

Hello Community,

i have following problem. I'am create from some files a PDF-File. The programm how do this for me is running in a DOS-Box. Now it can take a few time, until the programm is finished his process. So i wan't to create a 'wxProgressDialog' around my working-Process.

Here is my Sourcecode:

Code: Select all

// ..
MyPdfPrgDlg = new wxProgressDialog(_("Create file, please wait."), mess, 100, NULL);
MyPdfPrgDlg->Show(true);
// Execute the command
long MyProzId(wxExecute(command, wxEXEC_ASYNC));
while (wxProcess::Exists(MyProzId))
{
    // here i do something what i have to do
}
// Go on here, if the process is finished an closed.
// .. 
The code works fine. After work my 'DOS-Box' is closed. But now i have to wait a long time, to become a 'false' as answer of the function 'wxProcess::Exists(MyProzId)'. I'am still waiting, although the box is closed long time ago.

Now my question, is there any other (faster) way to ask 'if the process running'.

Thanks for any idea.

Ollow

DerKleineNik
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Sep 09, 2011 9:59 am

Re: wxProcess running

Post by DerKleineNik » Wed Nov 30, 2011 6:14 am

Hey,

why do you have to work with wxProcess? Isn't there just one thing to do in the programm at the same time?
Is there "OnTerminate" called at any time? if not your while loop starts over and over again.
Maybe it would be nice to post some more code to be able to understand the program a bit better

Ollow_AM
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Feb 26, 2010 10:22 am

Re: wxProcess running

Post by Ollow_AM » Wed Nov 30, 2011 7:35 am

Thank' s for answer.

Yes, "OnTerminate" is calling after my 'DOS-Box' is closed. But the loop allready answering the ID exists. I think its lasts some seconds until the Prozess-ID is released.

Yesterday evening i found a resolution. I don't use the static Funktion of wxProcess. I inherit from 'wxProcess' in mine own Class. And capture the Event 'wxEVT_END_PROCESS'. This looks now like this.... (Simple code):

Code: Select all

// ..  //
BEGIN_EVENT_TABLE(seiImportFiles, wxEvtHandler)
	EVT_END_PROCESS(ID_PDF_PROZESS, seiImportFiles::EndPdfProzess)
END_EVENT_TABLE()
// ..  //
   MyPdfProcessClass thisPdfProz(this, ID_PDF_PROZESS);

    if (!thisPdfProz.PdfProcessCommandExecute(command))
    {
        // Error
	return;
    }

    // Wait for End of Prozess or until a certain time has passed by
    while (waitForEndEvent)
    {
 	// do something, and looking for the 'wxEVT_END_PROCESS' -Event
    }
    // Go on here, if the process is finished an closed. 

Post Reply