Synchronizing SINGLE-threaded Windows apps?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Christoph Nahr (christoph.nahr_at_kynosarges.de)
Date: 04/15/04

  • Next message: Rick: "Aligning text in a Tooltip"
    Date: Fri, 16 Apr 2004 00:07:07 +0200
    
    

    Multi-threaded applications are well-supported by the .NET Framework.
    Surprisingly, it's much harder to handle single-threaded applications!

    I'm talking about the really nasty Windows habit of checking the
    message queue of the GUI thread at the most inopportune moments, i.e.
    whenever some seemingly innocuous method that relies on Win32 calls is
    executing. If the user happens to press a hotkey or click on some
    window icon (like "X") at this point, Windows makes a forced
    subroutine call to the handler for that event. Meanwhile, the
    previously executing application method is put on ice, as if it had
    called that new handler as a subroutine.

    I understand that this quasi-multitasking is the heritage of 16-bit
    Windows where there were no multiple threads. Well, it's really
    annoying today because it can cause synchronization problem when one
    message handler puts the application in a certain state that renders
    it unable to respond to certain other message handlers... and then,
    sure enough, those other handlers get triggered by user action while
    the first handler is still executing!

    That's really nasty because the usual thread synchronization methods
    don't work -- everything's executing on the same thread, so attempts
    to check a lock either fall through or block eternally.

    So far the only "solution" (more of a hack really) I've found is to
    simply return from the most recent message handler when I've found the
    application state inadequate, and perhaps manually save callback
    instructions for the handler that was already executing.

    Is there some kind of elegant solution for this problem? Any MSDN
    articles discussing this issue?

    -- 
    http://www.kynosarges.de
    

  • Next message: Rick: "Aligning text in a Tooltip"

    Relevant Pages

    • Synchronizing SINGLE-threaded Windows apps?
      ... I'm talking about the really nasty Windows habit of checking the ... subroutine call to the handler for that event. ... previously executing application method is put on ice, ... simply return from the most recent message handler when I've found the ...
      (microsoft.public.dotnet.framework.windowsforms)
    • Re: reading mouse wheel rotation in VB6
      ... gracefully and doesn't give Windows a hissy fit. ... the concept of subclassing should't be that daunting. ... Each object has their own message handler to interpret and handle ... ByVal uMsg As Long, _ ...
      (microsoft.public.vb.general.discussion)
    • Re: Exception/error returns - values or raised conditions?
      ... They can be ignored by the process executing when they trigger so I ... handler to be changed by the dynamic execution of the program. ... The key being that each instruction would trap to the handler ... I've not seen types 2 and 3 provided by any language (by the operating ...
      (comp.lang.misc)
    • RE: Are domain/machine names required when specifying roles
      ... only one handler is used to process a request. ... Authorization handler that will eliminate the need ... ASP.NET HTTP Modules and HTTP Handlers Overview ... | access and allow windows integrated and basic ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Re: Storing and Accessing email Addresses
      ... back to Windows, which will go about its business. ... You have written a handler for this occurence. ... you surrender control back to Windows. ... In fact, your program will also be a "state machine", with mCounter set at 27, ...
      (comp.lang.basic.visual.misc)