Page 1 of 1

Application freeze while long operation takes place

Posted: Mon Nov 12, 2012 9:01 pm
by TexasJimbo
I have an application that creates a 100+ meg database. It takes several minutes to complete the work.
I was trying to create a log window to write the status of my work as I go along so I can see where I am in the process.
If I don't touch anything, all works well, but in the background I want to bring up a DOS window (this is Windows btw),
to see the status of the db I am building in the background...when I do that the all the data in the log window disappears
and I don't see the status info in that window again until all work has completed and then it is all written at once.

Here is what I was doing...

Code: Select all

wxLogWindow *lw = new wxLogWindow(this, -1, true, false)
lw -> SetVerbose(true);

wxLogMessage(wxT("Beginning Work"));
....(intensive work)
wxLogMessage(wxT("Status Check Point 1"));
...(more intensive work)
wxLogMessage(wxT("Status Check Point 2"));
I didn't want to put this in a seperate thread which is what I think I might be looking at next, but am I using this logging correctly (if not, can someone post a simple example...just a simple popup message log to write messages to), and is there a way to get the screen to refresh even when you lose the focus?

Re: Application freeze while long operation takes place

Posted: Tue Nov 13, 2012 5:52 am
by Radek
IMO, your machine is choking from creating the database. The log messages are hanging somewhere in a queue and they do not have a chance even during a "starvation boost". IMO, you need a thread for creating the database. The thread will run at a priority slightly lower than a normal priority of a windowing app so that the usual window traffic will block the thread. This should restore responsibility of your machine. The thread will post (not send) log messages to the main thread. The main window should now be able to display the messages immediately.

IMO, you cannot pass without a thread.

Re: Application freeze while long operation takes place

Posted: Tue Nov 13, 2012 3:49 pm
by Manolo
MSW multitasking sucks.
A DOS window would get the lowest priority compared to your intensive CPU database creation.

What I would do in your case is create a wxTextCtrl and redirect log messages to it, just as many wx'samples do.
So, MSW will not split tasks and assign them different priorities, because all of it is in just only place: your app.

If you get your intensive job inside a thread, better. But I don't think it's trully required.

Another subject is that your app may let some time for the rest of apps, or MSW may get near irresponsive.

Re: Application freeze while long operation takes place

Posted: Wed Nov 14, 2012 1:20 pm
by catalyn269
What you need if wxApp::wxYield() or wxApp::wxSafeYield() from <wx/app.h>
This should flush the event loop and will keep your log window up to date.
Call it after each wxLogMessage call.

Good luck !