You pass it as an Object
in the last parameter to BeginGetRequestStream
. Currently you have:
Dim result As IAsyncResult = CType(request.BeginGetRequestStream(AddressOf GetRequestStreamCallback, request), IAsyncResult)
You're passing the result
in the state
parameter, and that value gets set in the AsyncState
property of the passed IAsyncResult
.
If you want to pass two values, you have some choices:
- Create a new object that has the
result
andindex
values as separate properties. - Create an array of
Object
where the first item is the request and the second is the index. You can then get theAsyncState
property, case it to an object array, and peel out the items. - Create a Tuple from your two values, and pass that
Tuple
in thestate
parameter.
I prefer the second because it's so easy, but creating a Tuple
is cleaner (i.e. type-safe) and almost as easy. I have a C# example of the second method at https://stackoverflow.com/a/4555766/56778.