ThreadPool.QueueUserWorkItem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pmclinn

    #1

    ThreadPool.QueueUserWorkItem

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


    ThreadPool.Queu eUserWorkItem(A ddressOf WriteFiles)


    Public Sub WriteFiles(ByVa l stateInfo As Object)

    End Sub

  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: ThreadPool.Queu eUserWorkItem

    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.Queu eUserWorkItem(A ddressOf WriteFiles, variable)



    Public Sub WriteFiles(ByVa l stateInfo As Object)
    Dim variable As String = DirectCast(stat eInfo, String)

    ...

    End Sub

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

    Public Class WriteFilesParam eters
    Public Variable1 As String
    Public Variable2 As String
    Public Variable3 As Integer
    End Class

    Dim variable As WriteFilesParam eters
    ThreadPool.Queu eUserWorkItem(A ddressOf WriteFiles, variable)



    Public Sub WriteFiles(ByVa l stateInfo As Object)
    Dim variable As WriteFilesParam eters = DirectCast(stat eInfo,
    WriteFilesParam eters)

    ...

    End Sub


    Hope this helps
    Jay


    "pmclinn" <pmclinn@gmail. com> wrote in message
    news:1119277443 .914647.145450@ g43g2000cwa.goo glegroups.com.. .
    | In the code format below, is there any way to pass in a variable to the
    | writefiles proceedure?
    |
    |
    | ThreadPool.Queu eUserWorkItem(A ddressOf WriteFiles)
    |
    |
    | Public Sub WriteFiles(ByVa l stateInfo As Object)
    |
    | End Sub
    |


    Comment

    Working...