-
too much thinking?
so my program likes to blank out when it has too much thinking to do..
http://img.photobucket.com/albums/v4...chThinking.jpg
the point where it does this is when its searching inside a large number of files for a certain keyword or keywords.
how can i prevent this from happening? thanks
-
Make the process that's causing the stall a separate process/thread and that way it shouldn't have such an adverse affect on painting or user input.
Or look again at the resource-hogging process and see if you can't improve the way it does what it does.
-
i like the way you think...
but i tried making the process a seperate thread, however with what i have currently when i try to execute the seperate thread, i get an access violation.
i believe the violation exists somewhere in here..
Code:
DWORD WINAPI PreSearch(LPVOID lParam)
{
HWND hwnd = (HWND)lParam;
?
-
You have to understand that your entire program is dependent on the windows message loop to do all sorts of things (like respond to key presses, redraw the window, do the actual work).
You have to break up your search into more manageable chunks. An easy way to do this is to create a 'state' which records where you're at.
eg
Code:
struct state {
vector<string> filenames;
int currentfile;
vector<string> results;
bool updated;
} state;
On each WM_TIMER event say, you search the next file in the list and then return. If you found something, append to the results, and set updated to true.
When the redraw code next happens, it will see the state.updated and proceed to update the window with the latest search results.
This can be extended to searching directories for lists of files (like only search one dir at once, and have a queue of directories still to be searched).
-
mm.....so would i add code for processing to the wm_timer case? or leave the code in the function i have it in, and then when the wm_timer case gets sent a message have the struct there with the current file that the function is on and have it continue processing the next file. then once that file is processed, release control until the wm_timer case gets its turn again?
or am i completely missing it? lol
would it be possible for some pseudo-code? if you're that bored thatd be sweet...
thanks :]
-
> release control until the wm_timer case gets its turn again?
Yes, that's it.
Basically, you have to slice the task up into manageable bits.
Or you could use threads as mentioned by Ken, but that brings in a whole bunch of other problems to do with access to shared data.
-
mm...so how do i know when wm_timer gets its turn? something like
Code:
if (WM_TIMER)
{
// CODE
}
? i dont imagine thatd be a good way of doing things but i've been wrong in the past. lol
-
The WM_TIMER message gets posted to your window like any other message. Just handle it in your window procedure's case statement, and perform a chunk of your processing as Salem suggested.
-
Code:
struct state {
vector<string> filenames;
int currentfile;
vector<string> results;
bool updated;
} elephant;
...
case WM_TIMER:
take_a_bite( &elephant );
break;
Just keep nibbling away until you've eaten the elephant - no indegestion :)
-
hahaha. i think i get it now.
i'll have to test it out later...
thanks :]
but i dont know if the conversion from .c to .cpp is going to go over too well for my program... =\