Ода wxYield

March 11th, 2010 Begemot

Знаете ли вы о wxYield? Если нет, то радуйтесь, потому я что я даю вам в руки поистине мощнейший инструмент. Это маленькая функция, название и назначение которой, я все никак не могу запомнить (!), способна творить чудеса.

bool Yield(bool onlyIfNeeded = false)

Yields control to pending messages in the windowing system. This can be useful, for example, when a time-consuming process writes to a text window. Without an occasional yield, the text window will not be updated properly, and on systems with cooperative multitasking, such as Windows 3.1 other processes will not respond.

Caution should be exercised, however, since yielding may allow the user to perform actions which are not compatible with the current task. Disabling menu items or whole menus during processing can avoid unwanted reentrance of code: see ::wxSafeYield for a better function.

Note that Yield() will not flush the message logs. This is intentional as calling Yield() is usually done to quickly update the screen and popping up a message box dialog may be undesirable. If you do wish to flush the log messages immediately (otherwise it will be done during the next idle loop iteration), call wxLog::FlushActive.

Calling Yield() recursively is normally an error and an assert failure is raised in debug build if such situation is detected. However if the onlyIfNeeded parameter is true, the method will just silently return false instead.

Если вдруг у вас падает программа, при закрытии\выходе\в деструкторе и у вас есть окно. Обязательно попробуйте wxYield. Уже три раза я избавлялся от необъяснимых падений, просто добавив ее вызов, чудесно, не правда ли?:)

Последний раз был сегодня, программа падает при рестарте компьютера или выходе пользователя из системы, только на XP и только если у нас установлен PuntoSwitcher… я конечно всеми фибрами души грешил на последний, но все равно пытался найти и исправить ошибку. И что бы вы думали? wxYield  в деструкторе главного окна, спасла положение.

Странно падает программа?
Лишь ошибку видишь ты?
wxYeld расставь по коду,
и еще раз посмотри!

Экспромт родился:)