The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,224 other subscribers

Archive for May 21st, 2013

Windows Message Loop and Application Reentrancy

Posted by jpluimers on 2013/05/21

One of the things you must be careful with is reentrancy in your application through a message loop.

The most obvious way is Application.ProcessMessages: it will loop until all messages from the Windows message queue are processed, whether your application is ready for them or not.

A less obvious way is because of modal dialogs or forms. They have their own message loop which might cause global reentrancy in your application (for instance through TTimer objects).

That was the case for this problem: stack overflow with repeated DispatchMessageW in the call stack.

A couple of ways to try to avoid these issues:

  • Don’t cause a secondary message loop.
    You can refrain from calling Application.ProcessMessages, but you cannot always avoid modal dialogs.
  • Protect each of your event handlers by disabling the path to it as soon as it gets called.
    This means disabling the Enabled property for instance of TTimer, TControl, TAction, or other objects that cause events.

–jeroen

via: windows – stack overflow with repeated DispatchMessageW in the call stack – Stack Overflow.

Posted in Delphi, Development, Software Development | 7 Comments »

 
%d bloggers like this: