This is a Ax-DLL (VBMThread10.DLL) for generic multithreading in VB6.
I know that there are plenty of libraries out there providing exactly this.
However, I want to share this approach and want to demonstrate how to use it.
There is only one public creatable component, the Thread class.
The Thread class is event driven and once created the new thread's main function is fired in the AsyncProcedure 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 AsyncProcedure event is a param SyncCallback. (IThreadSyncCallback class)
By this you can fire an synchronous callback. The current thread will be suspended, the method request is marshaled to the original thread.
On this SyncCallback event you can safely show forms. (as original thread)
I recommend to access project objects (classes, controls) only in the SyncCallback event.
Do not debug in the AsyncProcedure event, doing so will cause a crash.
The IDE can occasionally crash. (e.g. showing modal forms from user while a thread is running etc.)
But compiled executable should be quite stable in this regard.
Registration-Free (Side-by-side) is not supported. It must be registered normally in order to function.
List of revisions:
Attachment: VBMThread10 Ax-DLL project and a demo project.
I know that there are plenty of libraries out there providing exactly this.
However, I want to share this approach and want to demonstrate how to use it.
There is only one public creatable component, the Thread class.
The Thread class is event driven and once created the new thread's main function is fired in the AsyncProcedure 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 AsyncProcedure event is a param SyncCallback. (IThreadSyncCallback class)
By this you can fire an synchronous callback. The current thread will be suspended, the method request is marshaled to the original thread.
On this SyncCallback event you can safely show forms. (as original thread)
I recommend to access project objects (classes, controls) only in the SyncCallback event.
Do not debug in the AsyncProcedure event, doing so will cause a crash.
The IDE can occasionally crash. (e.g. showing modal forms from user while a thread is running etc.)
But compiled executable should be quite stable in this regard.
Registration-Free (Side-by-side) is not supported. It must be registered normally in order to function.
List of revisions:
Code:
17-Jun-2016
- Fixed a bug in the Suspended property.
15-Jun-2016
- First release.