Drivers Category

Drivers Update
Drivers

Activex dll threading model

Version: 44.47.18
Date: 04 March 2016
Filesize: 1.4 MB
Operating system: Windows XP, Visa, Windows 7,8,10 (32 & 64 bits)

Download Now

Visual Basic greatly simplifies the job of authoring in-process components that can be used safely and efficiently by multithreaded clients. All in-process components created with Visual Basic use apartment-model threading, to provide synchronous access to objects. Figure 8.4 shows how a multithreaded client uses a single-threaded in-process component. Figure 8.4  Multithreaded client using single-threaded DLL Note   For those who have done COM programming in C+, the client thread that handles all the calls to objects in the single-threaded in-process component will be the first thread that called Ole Initialize. Using a single-threaded DLL in this way is safe, but slow. Cross-thread marshaling is almost as slow as cross-process marshaling. You can improve the performance of an in-process component when it’s used with multithreaded clients by making the component multithreaded. To make an Active X DLL project multithreaded, select the desired threading options on the General tab of the Project Properties dialog box. Note   In-process components can only use the threads on which their clients create objects and make method calls. You cannot create additional threads within an in-process component, so the other threading options are unavailable for DLL projects. Important   Selecting the Unattended Execution option suppresses all forms of user interaction — including message boxes and system error dialogs. This is discussed in Event Logging for Multithreaded Components. Marking an Active X DLL project for apartment-model threading provides the following benefits: All of the objects a client creates on a given thread will be created in the same apartment (thread) in the DLL. Calls to these objects do not require cross-thread marshaling, making them more efficient. Because an object is only accessed on the thread where it was created, calls are synchronized (serialized).
 Note The following technical note has not been updated since it was first included in the online documentation. As a result, some procedures and topics might be out of date or incorrect. For the latest information, it is recommended that you search for the topic of interest in the online documentation index. This technical note explains how to enable apartment-model threading in an Active X control. Note that apartment-model threading is only supported in Visual C+ versions 4.2 or later. What Is Apartment- Model Threading? The apartment model is an approach to supporting embedded objects, such as Active X controls, within a multithreaded container application. Although the application may have multiple threads, each instance of an embedded object will be assigned to one apartment, which will execute on only one thread. In other words, all calls into an instance of a control will happen on the same thread. However, different instances of the same type of control may be assigned to different apartments. So, if multiple instances of a control share any data in common (for example, static or global data then access to this shared data will need to be protected by a synchronization object, such as a critical section. For complete details on the apartment threading model, please see Processes and Threads in the OLE Programmer's Reference. Why Support Apartment- Model Threading? Controls that support apartment-model threading can be used in multithreaded container applications that also support the apartment model. If you do not enable apartment-model threading, you will limit the potential set of containers in which your control could be used. Enabling apartment-model threading is easy for most controls, particularly if they have little or no shared data. If your control uses shared data, such as a static member variable, access to that data should be protected with a critical.
Let me begin my inaugural column for Code Guru by stating that I'm on a crusade-a crusade to stamp out bugs related to COM concurrency. COM features a concurrency mechanism that's capable of intercepting and serializing concurrent method calls to objects that were designed to process only one method call at a time. That mechanism centers around the notion of abstract boundaries called apartments. When I troubleshoot COM systems that don't work, probably 40% of the bugs that I find result from a lack of understanding of apartments. This deficiency of knowledge shouldn't be surprising, because apartments are at once one of the most complex areas of COM and also the least well documented. Microsoft's intentions were good, but when they introduced apartments to COM in Windows NT 3.51, they laid a mine field for unwary developers. Play by the rules and you can avoid stepping on mines. But it's hard to obey the rules when you don't know what the rules are. This article is the first in a two-part series that describes what apartments are, why they exist, and how to avoid the problems that they introduce. In Part 1, I'll describe COM's apartment-based concurrency mechanism. In Part 2, I'll provide a set of rules that you can follow to avoid some of the nastiest and most insidious bugs that afflict COM programmers. Apartment Basics An apartmentis a concurrency boundary; it's an imaginary box drawn around objects and client threads that separates COM clients and COM objects that have incompatible threading characteristics. The primary reason that apartments exist is to enable COM to serialize method calls to objects that aren't thread-safe. If you don't tell COM that an object is thread-safe, COM won't allow more than one call at a time to reach the object. Tell COM that the object is thread-safe, however, and it will happily allow the object to field concurrent method calls on.

© 2013-2016 gravexitwin.5v.pl