Library tutorials & articles
Using User-Interface Threads
Introduction
I've never done a user-interface thread that has windows or controls. On the other hand, the complement of a worker thread is not necessarily a thread that has user-interface objects. The complement of a worker thread is a thread that has a message pump. This is a subtle but important distinction, but one that I have either needed or exploited, depending on circumstances.
Apartment Threading
I don't pretend to be an expert on "apartment threading". I fell into it because I needed to know a small number of things about it, specifically, how to get a SAPI-enabled application to run.
The key to "Apartment threading" is that an object which is initialized should be initialized in a particular thread and all operations on that object must be performed from that same thread. Trying to do operations on the same object from other threads is not guaranteed to work correctly. The point of this being that the object can be then written without worrying about incorporating thread-safe operations, because only one thread ever accesses it.
The Message Pump
What I needed to run SAPI in a separate thread was not a worker thread, but a thread with a message pump. The thread does not have to have GUI objects, and hence the name "User-Interface Thread" is a serious misnomer. The user interface may not even be relevant.
What SAPI requires is a message pump. So I had to start a "user-interface" thread. There were a couple problems, so this essay tries to capture my experience.
Related articles
Related discussion
-
C++ CATMULL-ROM
by tkruvgt (0 replies)
-
VS2005 app's won't run on another machine
by ted4444 (0 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
How to create a games like FIFA08
by mawcot (0 replies)
Related podcasts
-
Concurrency Pt. 2
Podcast (MP3): Download Hosts: Alexander Michael Guests: Recording venue: In this second part of our concurrency series Michael and Alexander talk about basic patterns for concurrent programming, such as Active and Monitor Object, Scoped Locking and ...
This thread is for discussions of Using User-Interface Threads.