ThreadPool.QueueUserWorkItem

  • Thread starter Thread starter pmclinn
  • Start date Start date
P

pmclinn

In the code format below, is there any way to pass in a variable to the
writefiles proceedure?


ThreadPool.QueueUserWorkItem(AddressOf WriteFiles)


Public Sub WriteFiles(ByVal stateInfo As Object)

End Sub
 
pmclinn,
You can pass any value via the stateInfo parameter.

For example, if I wanted to pass a String I could do something like:

Dim variable As String
ThreadPool.QueueUserWorkItem(AddressOf WriteFiles, variable)



Public Sub WriteFiles(ByVal stateInfo As Object)
Dim variable As String = DirectCast(stateInfo, String)

...

End Sub

If I wanted to pass more then one value I would define a Parameter Object,
something like:

Public Class WriteFilesParameters
Public Variable1 As String
Public Variable2 As String
Public Variable3 As Integer
End Class

Dim variable As WriteFilesParameters
ThreadPool.QueueUserWorkItem(AddressOf WriteFiles, variable)



Public Sub WriteFiles(ByVal stateInfo As Object)
Dim variable As WriteFilesParameters = DirectCast(stateInfo,
WriteFilesParameters)

...

End Sub


Hope this helps
Jay


| In the code format below, is there any way to pass in a variable to the
| writefiles proceedure?
|
|
| ThreadPool.QueueUserWorkItem(AddressOf WriteFiles)
|
|
| Public Sub WriteFiles(ByVal stateInfo As Object)
|
| End Sub
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top