Re: Problem with Multithread in VB6
- From: ValyaS <ValyaS@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 17 Jun 2006 09:13:02 -0700
I have a DLL written in C# and exposing COM interface
(ComInterfaceType.InterfaceIsDual.)
Events get raised by this DLL on their own threads (say from the Threadpool.)
In a VB6 client application, if I'll create an object "WithEvents" and write
an event handler, can I safely update GUI directly in this handler?
If not what would be your recommendations, tips, examples...?
My preference would be in VB6 event handler to collect received from the
event data in a collection and later to manage them in a Timer.
But how to lock the collection in VB6?
Thanks,
Valentina
"Tony Proctor" wrote:
An ActiveX EXE doesn't just "simulate" multi-threading Mike. It can be truly.
multi-threaded. Check out the 'Thread-per-Object' and 'Thread-Pool' project
properties.
VB6 works fine in STA type multi-threaded environments. This ActiveX EXE
mechanism is just one example of such an environment. Others include
MTS/COM+, and even IIS. Yes, when you use a VB6 DLL from ASP, it will be
executing on multiple ASP threads at the same time.
Although there are books showing how to get VB6 to work in an MTA type
multi-threaded environment, this is generally acknowledged to be a lot of
work. Plus you're in completely unsupported territory.
Tony Proctor
"Mike Sharpe" <MikeSharpe@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2607D4DC-B8F6-4A79-90AB-BBA04CAAB991@xxxxxxxxxxxxxxxx
VB is not multithreaded and the process in which you are attempting tocreate
threads is incorrect. There are some APIs that you can use but they canwhile
cause some serious problems. The only safe way to simulate multi-threaded
behavior is to use the ActiveX EXE project type. This is similar to a DLL
but that it launches in a seperate process. This allows it to process
your main application processes as well.have
"Crevit" wrote:
Hi friends,
I have tryed to create thread in VB6 but with few results
I know that VB6 doesn't support, in native kind, multithreading but I
_read that if I create apposite classes I can have good results
I have create thread with 2 classes: first class, Dispatcher
(instancing=public not creatable) manage my thread and then, the second
class that identifies my thread, clsThread(instancing=public multiuse)
This is my Sub Main used to create the main thread:
----------------------------
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumThreadWindows Lib "user32" _
(ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long)
0&)
As Long
Sub Main()
Dim frmMainForm As DispMain
Call EnumThreadWindows(App.ThreadID, AddressOf EnumThreadWndMain,
= 0
If mhwndVB = 0 Then
Err.Raise ERR_InternalStartup + vbObjectError, , _
"Internal error starting thread"
Else
Call GetWindowThreadProcessId(mhwndVB, mlngProcessID)
If FindWindow(vbNullString, CAPT_PROCESS & CStr(mlngProcessID))
firstThen
' This windows has not been found, so this process is the
instances
If App.StartMode = vbSModeStandalone Then
' Load a hidden form with a unique caption
mfrmForm.Caption = CAPT_PROCESS & CStr(mlngProcessID)
' The event Initialize of clsDispMain (Instancing =
' PublicNotCreatable) displays the main user interface
Set frmMainForm = New DispMain
Else
Err.Raise ERR_NoAutomation + vbObjectError, , _
"Application can't be started with Automation"
End If
End If
End If
End Sub
The Dispmain class, with the function crerateobject("clsThread")
atobject of clsThrread type and the adds them in a collection associating
and aevery object an ID.
The clsThread class instances,on the initialize, a form with a button
onetext box
when I click the button a cycle starts and in the text box the seconds
showed,
but when i start 2 forms and press the 2 buttons, a cycle stops and when
executefinishes start the other.
In what kind I can create asynchronous multithread? That allows to
2 job together in parallel kind?
Thanks in advances.
Crevit
- References:
- Problem with Multithread in VB6
- From: Crevit
- RE: Problem with Multithread in VB6
- From: Mike Sharpe
- Re: Problem with Multithread in VB6
- From: Tony Proctor
- Problem with Multithread in VB6
- Prev by Date: Re: Problem with Multithread in VB6
- Next by Date: DLL host application?
- Previous by thread: Re: Problem with Multithread in VB6
- Next by thread: wan adress
- Index(es):