RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
You are running a Visual Basic 6.0 component in a high throughput, multi-threaded application; such as COM+/MTS, Active Server Pages (ASP), or a Visual Basic 6.0 ActiveX EXE.
Performance degrades and/or the application encounters high CPU as the component services a large number of client requests.
The Visual Basic component may be performing an operation that results in a critical section convoy. Internally Visual Basic 6.0 uses critical sections to protect key data structures, which the Visual Basic run-time uses to maintain a wide range of per-thread project information. If the component is executing code that requires access to the critical section, multiple threads may be waiting to take ownership of the critical section. This causes a delay in each thread servicing its request. Performance may decline over time as more and more threads are created, with each one waiting to access the critical section.
Common scenarios for this to occur would be:
1. Calling procedures or variables stored in standard modules (.bas).
2. Making late bound calls on COM components.
3. Using Visual Basic intrinsic file I/O statements, such as Open, Close, Get, Put, Print, or Write.
Consider making the following changes to the Visual Basic component to help avoid critical section convoys in the Visual Basic run-time.
1. Where possible, move procedures and variables stored in standard standard (.bas) modules into class modules.
2. Modify the component to use early bound calls to COM components, rather than late bound calls.
3. If the component is using the Visual Basic intrinsic file I/O statements, use one of the following alternatives instead.
   a. Use the FileSystemObject from the Scripting run-time.
   b. Use the Win32 API ReadFile and WriteFile functions.
   165942 How To Write Data to a File Using WriteFile API
  Â
http://kbalertz.com/165942
(http://support.microsoft.com/default.aspx?scid=kb;en-us;165942)
  c. Reduce the number of times calling the file I/O get and put to read or write data. For example, read and/or write larger chunks of data at a time.
Related Knowledgebase Articles
========================
815053Â INFO: Avoid Global Variables in Visual Basic COM+ Components
http://kbalertz.com/815053
(http://support.microsoft.com/default.aspx?scid=kb;en-us;815053)
241896Â Threading issues with Visual Basic 6.0 ActiveX components
http://kbalertz.com/241896
(http://support.microsoft.com/default.aspx?scid=kb;en-us;241896)
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALSâ€) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.