This is a Ax-DLL (VBMThread11.DLL) for generic multithreading in VB6.
Current version: 1.1.2
There is only one public creatable component, the Thread class.
The Thread class is interface driven and once created the new thread's main function is fired in the BackgroundProcedure event.
In this event the background work will be done, as it will not lock or freeze the App.
But attention is required as showing Forms will crash VB.
Therefore in the BackgroundProcedure event is a param StatusCallback. (IThreadStatusCallback class)
By this you can fire an synchronous callback. The background thread will be suspended, the method request is marshaled to the main thread.
On this StatusCallback event you can safely show forms or report progress.
It is recommended to access project objects (classes, controls) only in the StatusCallback event.
Do not debug or use 'App.Path' in the BackgroundProcedure event, doing so will cause a crash. (Unless the DebugMode property was set to True)
The source code of the project can also be viewed on GitHub.
Registration-Free (Side-by-side) solution for VBMThread11.DLL can be found here.
Notes:
- P-Code will fail. Native compilation is necessary.
List of revisions:
Code:
29-Apr-2017
- The Thread class is not event driven anymore. All "events" are fired now trough an IThread interface.
- Included mandatory Owner parameter in the Create method. That owner will receive the IThread events.
Also included an optional Key parameter that helps to identify multiple threads on the same owner.
- Renamed event 'AsyncProcedure' to 'BackgroundProcedure' and 'SyncCallback' to 'StatusCallback'.
- Included event 'Complete' that fires after the thread ran to completion or was canceled.
- Optional Wait parameter included in the Terminate method.
- Included the ThreadData class that will be passed along the BackgroundProcedure and Complete event.
- Included Cancel method. This method sets the CancellationPending property to True in the ThreadData.
How fast the cancellation is done depends on the code in the background procedure and if the developer respects the cancellation request.
- Included DebugMode property. If set to True the background thread runs synchronous to the main thread.
This does allow to safely set breakpoints and perform debugging in the IDE.
17-Jun-2016
- Fixed a bug in the Suspended property.
15-Jun-2016
- First release.
Attachment: VBMThread11 Ax-DLL project and a demo project.