Callbacks w/ Multiple Server Objects?
Hi:
I'm trying to do something that is backward to every example I see.
I want to create ONE 'Client' that can create MULTIPLE Asynchronous ActiveX 'Servers' and keep track of them.
Each 'Server' instance will perform a task (email a set of people) and then tell the Client:
1. who it is (this particular instance)
2. It's Status (complete; error; etc.)
3. What the Error is if there is one.
4. Then DIE!
Basically, I'm trying to write a multithreaded mass emailer.
My problem is, my Client can only seem to see ONE instance of the Server.
In the Event Proc on the client it prints 10 of the SAME Key & CAnalysisID.
Also, the (and only one) Server keeps running after the Client Ends.
How can I make this work right?
Heres the code.
<CLIENT>
<code>
Option Explicit
Private WithEvents oCA As AECEmailer.CAnalysis
Private CACount As Integer
Friend Sub DoBlast()
Dim i As Integer
CACount = 0
For i = 0 To 10
Set oCA = New AECEmailer.CAnalysis
oCA.CAnalysisID = 345 + i
oCA.Key = i
oCA.StartProcess
CACount = CACount + 1
Next
WaitUntilDone
End Sub
Private Sub oCA_Status(ByVal nStatus As Long, nKey As Long, nCAnalysisID As Long, sError As String)
Debug.Print nStatus & ", " & nKey & ", " & nCAnalysisID & ", " & sError
CACount = CACount - 1
End Sub
Private Sub WaitUntilDone()
Do Until CACount = 0
DoEvents
Loop
End Sub
</code>
</CLIENT>
<SERVER>
<code>
Private WithEvents Tmr As Timer
Private nKey As Long
Private nCAnalysisID As Long
Public Event Status(ByVal Status As Long, Key As Long, CAnalysisID As Long, Error As String)
Private Sub Class_Initialize()
Set fm = New fmTmr
Load fm
Set Tmr = fm.tmrStart
End Sub
Public Sub StartProcess()
Tmr.Enabled = True
End Sub
Private Sub DoBlast()
RaiseEvent Status(0, nKey, nCAnalysisID, "Success")
End Sub
Public Property Get Key() As Long
Key = nKey
End Property
Public Property Let Key(ByVal vNewValue As Long)
nKey = vNewValue + 3
End Property
Public Property Get CAnalysisID() As Long
CAnalysisID = nCAnalysisID + 5
End Property
Public Property Let CAnalysisID(ByVal vNewValue As Long)
nCAnalysisID = vNewValue
End Property
Private Sub Tmr_Timer()
DoBlast
End Sub
</code>
</SERVER>
|