Multi-Threaded 'Get' Example (wodHttpDLX)
Can anyone post a simple example of a simple multi-threaded 'Get'?
Re: Multi-Threaded 'Get' Example
Hi Greg,
What environment are you using?
You can use the component in multi-threaded applications, but you need to keep it apartment threaded (the component can only be used in the same thread it was created).
However, why don't you simply use multiple instances of the component?
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Hi Greg,
What environment are you using?
You can use the component in multi-threaded applications, but you need to keep it apartment threaded (the component can only be used in the same thread it was created).
However, why don't you simply use multiple instances of the component?
Regards,
Damba
I'd be happy to. Can you or someone else provide a simple example?
Thanks...
Oh! Using XP in development, but must also be able to run in Vista environment...
Re: Multi-Threaded 'Get' Example
Greg,
It's simple as declaring two instances, something like this (VB6 syntax):
Dim withevents http1 as wodHttpDLXCom
Dim withevents http2 as wodHttpDLXCom
and initializing them using New statements:
Set http1 = new wodHttpDLXCom
Set http2 = new wodHttpDLXCom
Ofcourse, you can also use an array to create multiple instances.
Hope this helps.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Damba,
Thanks for the example...
In trying to use an array, this does not appear to work:
Dim WithEvents http1(3) As wodHttpDLXCom
Can you provide an example of using an array?
Also it seems with blocking on, each thread/instance will have to wait on the other to complete...
What is the implication of setting blocking off? I was wondering if it were possibily to use it asycnronously.
Greg
Greg,
It's simple as declaring two instances, something like this (VB6 syntax):
Dim withevents http1 as wodHttpDLXCom
Dim withevents http2 as wodHttpDLXComand initializing them using New statements:
Set http1 = new wodHttpDLXCom
Set http2 = new wodHttpDLXComOfcourse, you can also use an array to create multiple instances.
Hope this helps.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Hi Greg,
Unfortunately, when declaring component as array, WithEvents statement is invalid. However, you can do something like this:
[code]Option Explicit
Dim http(5) As wodHttpDLXCom
Implements IwodHttpNotify
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Set http(i) = New wodHttpDLXCom
Set http(i).Notification = Me
Next
End Sub
Private Sub IwodHttpNotify_ClientCertRequired(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End Sub
Private Sub IwodHttpNotify_Connected(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End Sub
Private Sub IwodHttpNotify_Disconnected(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal ErrorCode As Long, ByVal ErrorText As String)
End Sub
Private Sub IwodHttpNotify_Done(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal ErrorCode As Long, ByVal ErrorText As String)
End Sub
Private Sub IwodHttpNotify_HeadersDone(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End Sub
Private Sub IwodHttpNotify_HostCertificate(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal Cert As wodHttpDLXComLib.ICertificate, ByVal ErrorCode As Long, ByVal ErrorText As String, Accept As Boolean)
End Sub
Private Sub IwodHttpNotify_Progress(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal Position As Long, ByVal Total As Long)
End Sub
Private Sub IwodHttpNotify_Redirect(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, URL As String, Allow As Boolean)
End Sub
Private Sub IwodHttpNotify_StateChange(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal OldState As wodHttpDLXComLib.HttpStates)
End Sub
Private Sub IwodHttpNotify_Progress64(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal PositionLo As Long, ByVal PositionHi As Long, ByVal TotalLo As Long, ByVal TotalHi As Long)
End Sub
[/code]
In this sample, I used Notification interface. In this case, each method (event) has Owner parameter which provides you with reference to instance of component that raised the event. Can you try something like that?
As for using blocking, you're correct. Each method that is executed will block the rest of the code until it finishes executing. To avoid that you should use Events.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Damba,
Much appreciated...
So I should set blocking to OFF, and capture the response in 'IwodHttpNotify_Done' when the call is done, such as:
strResponse=http(5).Response.Body?
Greg
Hi Greg,
Unfortunately, when declaring component as array, WithEvents statement is invalid. However, you can do something like this:
[code]Option Explicit
Dim http(5) As wodHttpDLXCom
Implements IwodHttpNotifyPrivate Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Set http(i) = New wodHttpDLXCom
Set http(i).Notification = Me
Next
End SubPrivate Sub IwodHttpNotify_ClientCertRequired(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End SubPrivate Sub IwodHttpNotify_Connected(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End SubPrivate Sub IwodHttpNotify_Disconnected(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal ErrorCode As Long, ByVal ErrorText As String)
End SubPrivate Sub IwodHttpNotify_Done(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal ErrorCode As Long, ByVal ErrorText As String)
End SubPrivate Sub IwodHttpNotify_HeadersDone(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom)
End SubPrivate Sub IwodHttpNotify_HostCertificate(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal Cert As wodHttpDLXComLib.ICertificate, ByVal ErrorCode As Long, ByVal ErrorText As String, Accept As Boolean)
End SubPrivate Sub IwodHttpNotify_Progress(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal Position As Long, ByVal Total As Long)
End SubPrivate Sub IwodHttpNotify_Redirect(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, URL As String, Allow As Boolean)
End SubPrivate Sub IwodHttpNotify_StateChange(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal OldState As wodHttpDLXComLib.HttpStates)
End SubPrivate Sub IwodHttpNotify_Progress64(ByVal Owner As wodHttpDLXComLib.IwodHttpDLXCom, ByVal PositionLo As Long, ByVal PositionHi As Long, ByVal TotalLo As Long, ByVal TotalHi As Long)
End Sub
[/code]In this sample, I used Notification interface. In this case, each method (event) has Owner parameter which provides you with reference to instance of component that raised the event. Can you try something like that?
As for using blocking, you're correct. Each method that is executed will block the rest of the code until it finishes executing. To avoid that you should use Events.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Greg,
That's correct. Or, you can use Owner.Response.Body, the effect is the same.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Damba,
Thanks again...
Just to clarify:
strResponse=http(5).Response.Body
OR
strResponse=http(5).Owner.Response.Body?
Greg,
That's correct. Or, you can use Owner.Response.Body, the effect is the same.
Regards,
Damba
Re: Multi-Threaded 'Get
Damba,
Sorry! I see 'Owner' is here: IwodHttpNotify_Done(ByVal Owner
How would I know which 'Thread/Instance' it belonged to?
(e.g., http1(1)..http1(5))?
Greg
Damba,
Thanks again...
Just to clarify:
strResponse=http(5).Response.Body
OR
strResponse=http(5).Owner.Response.Body?Greg,
That's correct. Or, you can use Owner.Response.Body, the effect is the same.
Regards,
Damba
Re: Multi-Threaded
Damba,
...just noticed Owner.LicenseKey too...
So I need to set the licensekey for each instance too I would suppose, correct?
Greg
Damba,
Sorry! I see 'Owner' is here: IwodHttpNotify_Done(ByVal Owner
How would I know which 'Thread/Instance' it belonged to?
(e.g., http1(1)..http1(5))?Greg
Damba,
Thanks again...
Just to clarify:
strResponse=http(5).Response.Body
OR
strResponse=http(5).Owner.Response.Body?Greg,
That's correct. Or, you can use Owner.Response.Body, the effect is the same.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Greg,
strResponse=http(5).Response.Body and strResponse=http(5).Owner.Response.Body isn't the same. Actually, http(5).Owner.Response.Body doesn't exist at all, so you would receive an error when you try to access it.
However, the reference provided as Owner is always the one that triggered the event (in this case the IwodHttpNotify_Done procedure).
Also, we implemented a new property for the main object (Tag property), which you can use to set to something that will allow you to identify objects.
However, you will need to update to latest version in order to get this property.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Damba,
Great! Is it already done??? Sounded like it though I wouldn't imagine you got it done so fast.
Nevertheless I went ahead and requested an update.
Greg
Greg,
strResponse=http(5).Response.Body and strResponse=http(5).Owner.Response.Body isn't the same. Actually, http(5).Owner.Response.Body doesn't exist at all, so you would receive an error when you try to access it.
However, the reference provided as Owner is always the one that triggered the event (in this case the IwodHttpNotify_Done procedure).
Also, we implemented a new property for the main object (Tag property), which you can use to set to something that will allow you to identify objects.
However, you will need to update to latest version in order to get this property.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Greg,
Yes, it's implemented already. You should find Tag property under the main wodHttpDLX object.
Regards,
Damba
Re: Multi-Threaded 'Get' Example
Damba,
I just downloaded and installed 1.6.1 and saw it there...
I really appreciate your help and your getting back to me quickly on this as well as your follow through...
Thanks again,
Greg
Greg,
Yes, it's implemented already. You should find Tag property under the main wodHttpDLX object.
Regards,
Damba
Re: Multi-Threaded 'Get
Damba,
Another question...
I'm assuming I can get notified in IwodHttpNotify_Disconnected when a thread is available for reuse...
Say I have an array of 3, http1(2), and I have 9 sites....
I do the first three gets in my loop and I guess set up a second loop to poll and reuse threads until I've done all 9 gets?
Is this how it's done or is there some other accepted method of handling the polling to determine when to launch the next thread until all 'Gets' have been executed?
Could you provide a quick example/snippet of what's an accepted method in using 'IwodHttpNotify'.
Thanks,
Greg
Damba,
I just downloaded and installed 1.6.1 and saw it there...
I really appreciate your help and your getting back to me quickly on this as well as your follow through...
Thanks again,
Greg
Greg,
Yes, it's implemented already. You should find Tag property under the main wodHttpDLX object.
Regards,
Damba
Re: Multi-Threaded
Hi Greg,
wodHttpDLX Done Event (IwodHttpNotify_Done) will be fired when wodHttpDLX complete request. If you want to use same thread you can call there next request.
Can you try that and let us know ho wit goes?
Drazen
Re: Multi-Threaded
Drazen,
Sorry for the delay in reporting back on this...
Your advice worked!
Thank a bunch...
Now I'm to the next thing. That is what brought me back to the site and caused me to remember I had forgotten to close this thread.
My next question involves the component. Thanks a lot for helping me through this question.
Greg
Hi Greg,
wodHttpDLX Done Event (IwodHttpNotify_Done) will be fired when wodHttpDLX complete request. If you want to use same thread you can call there next request.Can you try that and let us know ho wit goes?
Drazen