Application freeze while long operation takes place

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
Knows some wx things
Knows some wx things
Posts: 28
Joined: Sun May 04, 2008 6:41 pm

Application freeze while long operation takes place

Post by TexasJimbo » Mon Nov 12, 2012 9:01 pm

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?

Super wx Problem Solver
Super wx Problem Solver
Posts: 286
Joined: Sun Sep 11, 2011 7:17 am

Re: Application freeze while long operation takes place

Post by Radek » Tue Nov 13, 2012 5:52 am

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.

Can't get richer than this
Can't get richer than this
Posts: 713
Joined: Mon Apr 30, 2012 11:07 pm

Re: Application freeze while long operation takes place

Post by Manolo » Tue Nov 13, 2012 3:49 pm

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.

Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Dec 12, 2007 2:40 pm

Re: Application freeze while long operation takes place

Post by catalyn269 » Wed Nov 14, 2012 1:20 pm

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 !
Just me!

Post Reply