Page 1 of 1

wxDirTraverser Issues

Posted: Sat Oct 10, 2009 8:48 pm
by Stewie
I currently have a wxDirTraverser that searches a client's specified folder for a list of matching files for his use. However, if the client should realize that he has typed in the wrong criterion, and is searching, say, the entire C: drive, I would like for him to be able to stop searching.

So, using Yield() and setting up a Stop button, I set a class variable called "m_TerminateSearch" to true. If the Traverser detects that this is true, it returns wxDIR_STOP using this code:

Code: Select all

if (wxGetApp().m_TerminateSearch) {
	wxGetApp().Yield();
	return wxDIR_STOP;
}
However, when I hit the Stop button (or set m_TerminateSearch to true in any way), the application freezes for a short while as if it's traversing the rest of the directory anyway. (A quick test confirms that indeed, it does go through the rest of the files anyway.)

How can I force the Traverser to actually STOP searching?

Posted: Mon Oct 12, 2009 9:19 am
by van_user

Code: Select all

if (wxGetApp().m_TerminateSearch) {
        wxGetApp().Yield();
        return wxDIR_STOP;
}
For what purpose you use Yield( ) here? Maybe this line not need?

Posted: Tue Oct 13, 2009 2:19 am
by Stewie
I've tried without as well. I just used that to make sure the program didn't turn to a white screen upon termination. Neither way prevented the freeze-up.

Posted: Tue Oct 13, 2009 9:03 am
by xaviou
Hi
In your code, the Yield() is called only if wxGetApp().m_TerminateSearch is set to true.

But I think the button event that allow you to stop the search can't be treated, because the app is running, and the search in a too big job.

Try to put the Yield before, and it sould work better :

Code: Select all

wxGetApp().Yield();
if (wxGetApp().m_TerminateSearch) return wxDIR_STOP;
Of course, this will slow you app, so you can do somethind to call this 1 time evvery 10 files founded, for example.

Regards

Xav'

Posted: Wed Oct 14, 2009 9:46 pm
by Stewie
No luck; putting it before (or after and outside of the statement) had no effect. I also tried removing it entirely, which had no effect either.