Fabrice Harari International WinDev Consultant

Home         About Fabrice         WinDev Files        Products        Fabrice's blog         Consulting        Contact Fabrice        Links

My status

Random errors: what can cause them

Using UpdateWindow API call:
Of course, not everybody uses UpdateWindow in the first place... A lot of developers don't even know this API.... So first, a quick overview on why and how I'm using it...

{AmazonLinks}


When you are processing a file (by example) and you have to do a complex statistical calculation of all of its records, you may want to display the name of the record currently processed... At this point, you should know that to do that, you will have to use the multitask instruction. If you already know the MultitaskRedraw instruction, stay with me, because this can interest you anyway...

In that case, the multitask instruction problem is that it's going to slow down your process... a LOT... And that's at least one of the reason why the MultitaskRedraw instruction has been introduced somewhere between the 5.5 and the 9 versions.

Let's say that a process duration is around 1 hour without display... With the display and the multitask, you can double that time, in some case, you can even have it worse than that (depends of the hardware you are using and your process)...

By using the API call UpdateWindow, you are requesting from the API that your window be refreshed. You can even give the handle of the FIELD you are using for the display instead of the handle of the whole window for an even faster processing... And suddenly you can display the name of every record you are processing and see no noticeable time difference.

Once again, I'm not privy to any PCSoft insider information, but it seems to me that the MultitaskRedraw instruction is doing precisely that, calling the UpdateWindow API...

So how can that create a random error? The good news is that it's not easy... And it seems that it's OS dependent... So if your program is supposed to work only on recent machine with the last version of Windows on it, you are probably safe... Bit if it can also work on older version like W98, be careful...

I had the problem when running a lengthy process (even with the UpdateWindow optimization, it was running for something around 1h30 or 2 hours). After perhaps 45 minutes of processing, I had a windows crash because of a stack overflow...

It took me some time to figure out that the UpdateWindow call that I had been using for years was responsible for that... It seems that this call is (like any other API call) setting information in one of windows stack... And my process was so long, so resource intensive, and so not releasing the processor ever by doing a multitask that the stack was never cleaned.... After a while, the stack overflowed!

At this point, I modified my method encapsulating UpdateWindow to add a counter, and each 'n' calls (generally 100), I did a multitask() instead of the UpdateWindow. The multitask here is giving the OS enough time to clean after itself and solves the problem.

 

Google
 
Web www.fabriceharari.com
Links:


Last modified Friday, March 17, 2006 12:09 PM central time