Groups | Blog | Home
all groups > vb.net > april 2005 >

vb.net : How can I prevent this from Late Binding?


gregory_may
4/18/2005 3:48:25 PM
I am using the thread pool.

I would like to prevent late binding, but cant figure out how. When the
WaitCallback function is called, it expects a function prototype with type
OBJECT. My rotuine that does the real work, needs it as a string Array.
Whats the best peformance way to handle this?

Thanks!


Main Routine.

.



Dim dataArray() As String



If Not ThreadPool.QueueUserWorkItem _

(New WaitCallback(AddressOf process_Inbound_Message_deligate),
dataArray) Then

Debug.WriteLine("Could not queue to thread pool.")

End If



.

End of Main Routine.



Private Sub process_Inbound_Message_deligate(ByVal RecieveBuffer As Object)

'We are "late binding" & converting the object back to a byte array.
Not sure

'What the performance of this is?

process_Inbound_Message(RecieveBuffer)

End Sub



Private Sub process_Inbound_Message(ByVal DataArray() As String)

'Do work here with DataArray()





End Sub

gregory_may
4/18/2005 4:14:56 PM
Ok, I figured out another problem. I actually want to pass 2 parms to the
process_Inbound_Message_deligate. I could create a structure for this, but
I need the objects ByRef not ByVal. (How do you create a structure with
ByRef items?

Is this possible?

This is sort of what I want? But, I have not idea how to get a Pointer to
a Class or a pointer to a String array. Maybe there is another way to pass
in multiple parms to a ThreadPool? Help. I am being sucked into a black
hole of pointers.




'Do I need a structure to get multiple objects into a threadpool object?

Public Structure ThreadPoolPayload

Public StringArray_Ptr As IntPtr

'Should be a Pointer to a very large String array (not a copy)

Public Client_ptr As IntPtr

'Should be a Pointer to a class instance (not a copy).

End Structure





Main Routine.

.



Dim dataArray() As String



If Not ThreadPool.QueueUserWorkItem _

Dim MyThreadPoolPayload As New ThreadPoolPayload



MyThreadPoolPayload.StringArray_Ptr =
GetPointerToThisObject(dataArray)

MyThreadPoolPayload.Client_Ptr = GetPointerToThisObject(sender)



(New WaitCallback(AddressOf process_Inbound_Message_deligate),
MyThreadPoolPayload) Then

Debug.WriteLine("Could not queue to thread pool.")

End If



.

End of Main Routine.





Private Sub process_Inbound_Message_deligate(ByVal Payload As Object)

'We are "late binding" & converting the object back to a byte array.
Not sure

'What the performance of this is?

process_Inbound_Message(Payload)

End Sub





Private Sub process_Inbound_Message(ByVal MyThreadPoolPayload As
threadPoolPayload)

'Do work here with MyClient and MyStringArray



End Sub










[quoted text, click to view]

Cor Ligthert
4/19/2005 12:00:00 AM
Gregory,

It is seldom that this does not work.
CType (MyObject, String())

This is a conversion,

When it is real a cast than you can better use
DirectCast(MyObject(), String())

I hope this helps,

Cor

gregory_may
4/19/2005 1:33:35 PM
This directCast did the trick!
Thanks!

[quoted text, click to view]

AddThis Social Bookmark Button