<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://groupkos.com:443/chrysalis/index.php?action=history&amp;feed=atom&amp;title=VB6_DoEvents_HyperGeekery</id>
	<title>VB6 DoEvents HyperGeekery - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://groupkos.com:443/chrysalis/index.php?action=history&amp;feed=atom&amp;title=VB6_DoEvents_HyperGeekery"/>
	<link rel="alternate" type="text/html" href="https://groupkos.com:443/chrysalis/index.php?title=VB6_DoEvents_HyperGeekery&amp;action=history"/>
	<updated>2026-11-25T05:09:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://groupkos.com:443/chrysalis/index.php?title=VB6_DoEvents_HyperGeekery&amp;diff=1752&amp;oldid=prev</id>
		<title>XenoEngineer: XenoEngineer moved page VB6 DoEvents in tight loops to VB6 DoEvents HyperGeekery without leaving a redirect</title>
		<link rel="alternate" type="text/html" href="https://groupkos.com:443/chrysalis/index.php?title=VB6_DoEvents_HyperGeekery&amp;diff=1752&amp;oldid=prev"/>
		<updated>2026-09-18T17:37:24Z</updated>

		<summary type="html">&lt;p&gt;XenoEngineer moved page &lt;a href=&quot;/chrysalis/index.php?title=VB6_DoEvents_in_tight_loops&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;VB6 DoEvents in tight loops (page does not exist)&quot;&gt;VB6 DoEvents in tight loops&lt;/a&gt; to &lt;a href=&quot;/chrysalis/index.php/VB6_DoEvents_HyperGeekery&quot; title=&quot;VB6 DoEvents HyperGeekery&quot;&gt;VB6 DoEvents HyperGeekery&lt;/a&gt; without leaving a redirect&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:37, 18 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>XenoEngineer</name></author>
	</entry>
	<entry>
		<id>https://groupkos.com:443/chrysalis/index.php?title=VB6_DoEvents_HyperGeekery&amp;diff=1751&amp;oldid=prev</id>
		<title>XenoEngineer: Created page with &quot;{{menuVB6}} &lt;div style=&quot;float:riGHT; WIDTH:425PX;&quot;&gt;__TOC__&lt;/div&gt; &lt;div style=&quot;background-color:#eee;   border:1px outset azure; padding:0 20px; max-width:860px; margin:0 auto; &quot;&gt; = Robust Event-Driven Architectures in Visual Basic 6 =  This article details the principles and best practices for building stable, event-driven applications in Visual Basic 6. It focuses on the often-misunderstood robustness of its single-threaded COM event model and the disciplined use of UI r...&quot;</title>
		<link rel="alternate" type="text/html" href="https://groupkos.com:443/chrysalis/index.php?title=VB6_DoEvents_HyperGeekery&amp;diff=1751&amp;oldid=prev"/>
		<updated>2026-09-18T17:36:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{menuVB6}} &amp;lt;div style=&amp;quot;float:riGHT; WIDTH:425PX;&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt; &amp;lt;div style=&amp;quot;background-color:#eee;   border:1px outset azure; padding:0 20px; max-width:860px; margin:0 auto; &amp;quot;&amp;gt; = Robust Event-Driven Architectures in Visual Basic 6 =  This article details the principles and best practices for building stable, event-driven applications in Visual Basic 6. It focuses on the often-misunderstood robustness of its single-threaded COM event model and the disciplined use of UI r...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{menuVB6}}&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:riGHT; WIDTH:425PX;&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color:#eee;   border:1px outset azure; padding:0 20px; max-width:860px; margin:0 auto; &amp;quot;&amp;gt;&lt;br /&gt;
= Robust Event-Driven Architectures in Visual Basic 6 =&lt;br /&gt;
&lt;br /&gt;
This article details the principles and best practices for building stable, event-driven applications in Visual Basic 6. It focuses on the often-misunderstood robustness of its single-threaded COM event model and the disciplined use of UI responsiveness techniques, particularly in the context of modern operating systems.&lt;br /&gt;
&lt;br /&gt;
== The COM Event Model: A Foundation for Stability ==&lt;br /&gt;
&lt;br /&gt;
The power of component-based design in VB6 is realized through its implementation of Connection Points, which manifest as the `WithEvents` keyword and the `RaiseEvent` statement. This allows for clean, decoupled communication between class instances. A common misconception is that this system is fragile; in reality, its single-threaded nature makes it exceptionally predictable and robust.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Key Principles:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*   &amp;#039;&amp;#039;&amp;#039;Single-Threaded Apartment (STA) Model:&amp;#039;&amp;#039;&amp;#039; All standard VB6 components and code run on a single thread. This eliminates entire classes of bugs related to multi-threading, such as race conditions and deadlocks.&lt;br /&gt;
*   &amp;#039;&amp;#039;&amp;#039;Synchronous Event Execution:&amp;#039;&amp;#039;&amp;#039; A `RaiseEvent` call is not an asynchronous, &amp;quot;fire-and-forget&amp;quot; message. It is a direct, synchronous function call to all listening objects. The code that calls `RaiseEvent` is paused on the call stack and will not continue until all event handlers have completed their execution.&lt;br /&gt;
&lt;br /&gt;
This creates a deterministic event chain. If Object A raises an event handled by Object B, which in turn raises an event handled by Object C, the execution flow is a simple, deep call stack: C must finish before B can resume, and B must finish before A can resume.&lt;br /&gt;
&lt;br /&gt;
=== Example: A Simple Event Chain ===&lt;br /&gt;
Consider a source class that signals a change.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;vb&amp;quot;&amp;gt;&lt;br /&gt;
&amp;#039; In clsSource&lt;br /&gt;
Public Event DataChanged(ByVal newData As String)&lt;br /&gt;
&lt;br /&gt;
Public Sub DoWork()&lt;br /&gt;
    &amp;#039; ... work is done ...&lt;br /&gt;
    RaiseEvent DataChanged(&amp;quot;New Value&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A listener class handles this event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;vb&amp;quot;&amp;gt;&lt;br /&gt;
&amp;#039; In clsListener&lt;br /&gt;
Private WithEvents m_Source As clsSource&lt;br /&gt;
&lt;br /&gt;
Private Sub m_Source_DataChanged(ByVal newData As String)&lt;br /&gt;
    &amp;#039; This code executes as a direct result of the&lt;br /&gt;
    &amp;#039; RaiseEvent call in m_Source.&lt;br /&gt;
    Debug.Print &amp;quot;Listener received: &amp;quot; &amp;amp; newData&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This chain is as stable as a direct function call because, under the hood, that is precisely what it is.&lt;br /&gt;
&lt;br /&gt;
== The `DoEvents` Command: A Controlled Application of Re-entrancy ==&lt;br /&gt;
&lt;br /&gt;
While the single-threaded model provides stability, it presents a challenge for long-running tasks: a CPU-intensive loop will block the thread, freezing the user interface. The tool provided to mitigate this is `DoEvents`.&lt;br /&gt;
&lt;br /&gt;
`DoEvents` yields control from the currently running code to the Windows message queue, allowing the application to process pending events like UI repaints and user input. However, its power comes with a significant risk: &amp;#039;&amp;#039;&amp;#039;re-entrancy&amp;#039;&amp;#039;&amp;#039;. If not handled with discipline, `DoEvents` can allow code to be re-entered before it has completed, leading to state corruption.&lt;br /&gt;
&lt;br /&gt;
=== The Canonical Safe Pattern: The Throttled Worker Loop ===&lt;br /&gt;
The correct and stable use of `DoEvents` is within a self-contained, long-running loop where the program state is managed carefully.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Characteristics of the Safe Pattern:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*   The loop performs a divisible, iterative task (e.g., processing files, running calculations).&lt;br /&gt;
*   `DoEvents` is called periodically, not on every iteration, to prevent performance degradation (e.g., using `If i Mod 1000 = 0 Then`).&lt;br /&gt;
*   A well-defined communication channel, such as a public `Cancel` flag, is used to allow the UI to interrupt the loop. This flag is checked immediately after the `DoEvents` call.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;vb&amp;quot;&amp;gt;&lt;br /&gt;
&amp;#039; In a worker class&lt;br /&gt;
Public Event Progress(percentComplete As Integer)&lt;br /&gt;
Public Cancel As Boolean&lt;br /&gt;
&lt;br /&gt;
Public Sub LongRunningTask()&lt;br /&gt;
    Dim i As Long&lt;br /&gt;
    Const TOTAL_ITERATIONS As Long = 500000&lt;br /&gt;
&lt;br /&gt;
    Cancel = False &amp;#039; Ensure a clean start&lt;br /&gt;
&lt;br /&gt;
    For i = 1 To TOTAL_ITERATIONS&lt;br /&gt;
        &amp;#039; Perform one unit of work...&lt;br /&gt;
&lt;br /&gt;
        &amp;#039; --- Disciplined DoEvents Block ---&lt;br /&gt;
        If i Mod 1000 = 0 Then&lt;br /&gt;
            RaiseEvent Progress((i / TOTAL_ITERATIONS) * 100)&lt;br /&gt;
            DoEvents&lt;br /&gt;
&lt;br /&gt;
            &amp;#039; Immediately check for state changes from the UI&lt;br /&gt;
            If Cancel Then&lt;br /&gt;
                Exit For&lt;br /&gt;
            End If&lt;br /&gt;
        End If&lt;br /&gt;
    Next i&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This pattern provides UI responsiveness without sacrificing stability, as the re-entrancy is controlled and explicitly handled.&lt;br /&gt;
&lt;br /&gt;
== Architectural Considerations for Modern Operating Systems ==&lt;br /&gt;
&lt;br /&gt;
A key observation when running VB6 applications on Windows 10/11 is the apparent slowness of UI updates compared to the raw execution speed of a computational loop. This is not a flaw in VB6 but a fundamental shift in the Windows graphics architecture.&lt;br /&gt;
&lt;br /&gt;
*   &amp;#039;&amp;#039;&amp;#039;Classic (GDI):&amp;#039;&amp;#039;&amp;#039; In the Windows XP era, applications often drew directly to the screen via GDI. The path from a command like `Label1.Caption = &amp;quot;...&amp;quot;` to a visible pixel was very short.&lt;br /&gt;
*   &amp;#039;&amp;#039;&amp;#039;Modern (DWM):&amp;#039;&amp;#039;&amp;#039; Since Windows Vista, the Desktop Window Manager (DWM) composites the desktop. Applications draw to an off-screen buffer, and the DWM composites these buffers to create the final screen image. This process, while enabling modern effects like transparency, introduces significant latency.&lt;br /&gt;
&lt;br /&gt;
This latency means that a CPU-bound loop can complete millions of iterations in the time it takes for a single UI update to be rendered. Therefore, the practice of throttling `DoEvents` is more critical than ever. The modulus value used for throttling should be significantly larger on a modern system to batch UI updates effectively and prevent flooding the message queue with requests that the DWM cannot service in time.&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
💡 9728 prompt + 1307 completion = 11035 tokens&lt;br /&gt;
   Token budget: 9728 / 2097152&lt;br /&gt;
&lt;br /&gt;
🗣️  Xeno:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>XenoEngineer</name></author>
	</entry>
</feed>