Getting a reference to the actual background worker

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

    Getting a reference to the actual background worker

    I define a Background Worker as follows:

    Dim MyWorker(10) As System.Componen tModel.Backgrou ndWorker

    For n=1 to 10
    MyWorker(n)= New System.Componen tModel.Backgrou ndWorker
    AddHandler MyWorker (n).DoWork, AddressOf MyWorker_DoWork
    AddHandler MyWorker (n).RunWorkerCo mpleted, AddressOf MyWorker_AllDon e
    Next

    I launch the worker as follows with a parameter 'n'

    If Myworker(n).IsB usy = False Then
    MyWorker(n).Run WorkerAsync(n)
    End If

    When the thread ends, I want to get a reference to the actual thread that
    has ended. This will be the parameter 'n'. I can get a reference to the
    thread itself but I can't see a way of getting to 'n'


    Sub MyWorker_AllDon e(ByVal sender As Object, ByVal e As
    System.Componen tModel.RunWorke rCompletedEvent Args)
    Dim c As System.Componen tModel.Backgrou ndWorker =
    DirectCast(send er, System.Componen tModel.Backgrou ndWorker)


    'What can I put here?

    End Sub

    -Jerry


  • Armin Zingler

    #2
    Re: Getting a reference to the actual background worker

    "Jerry Spence1" <jerry.spence@s omewhere.co.uks chrieb
    Sub MyWorker_AllDon e(ByVal sender As Object, ByVal e As
    System.Componen tModel.RunWorke rCompletedEvent Args)
    Dim c As System.Componen tModel.Backgrou ndWorker =
    DirectCast(send er, System.Componen tModel.Backgrou ndWorker)
    >
    >
    'What can I put here?
    >
    End Sub

    Index = Array.IndexOf(M yWorker, sender)


    Armin

    Comment

    • Phill W.

      #3
      Re: Getting a reference to the actual background worker

      Jerry Spence1 wrote:
      Dim MyWorker(10) As System.Componen tModel.Backgrou ndWorker
      For n=1 to 10
      MyWorker(n)= New System.Componen tModel.Backgrou ndWorker
      AddHandler MyWorker (n).DoWork, AddressOf MyWorker_DoWork
      AddHandler MyWorker (n).RunWorkerCo mpleted, AddressOf MyWorker_AllDon e
      Next
      >
      I launch the worker as follows with a parameter 'n'
      >
      If Myworker(n).IsB usy = False Then
      MyWorker(n).Run WorkerAsync(n)
      End If
      >
      When the thread ends, I want to get a reference to the actual thread that
      has ended. This will be the parameter 'n'. I can get a reference to the
      thread itself but I can't see a way of getting to 'n'
      I've not used the BackgroundWorke r yet, but if it's anything like the
      other asynchronous methods, your 'n' should be taken as "state" data
      which, /if/ I read MSDN right, you should be able to get hold of through
      e.UserState.

      HTH,
      Phill W.

      Comment

      • Jerry Spence1

        #4
        Re: Getting a reference to the actual background worker

        That's brilliant!

        Thanks Armin

        -Jerry
        "Armin Zingler" <az.nospam@free net.dewrote in message
        news:upJR4LlaIH A.1132@TK2MSFTN GP06.phx.gbl...
        "Jerry Spence1" <jerry.spence@s omewhere.co.uks chrieb
        >Sub MyWorker_AllDon e(ByVal sender As Object, ByVal e As
        >System.Compone ntModel.RunWork erCompletedEven tArgs)
        > Dim c As System.Componen tModel.Backgrou ndWorker =
        >DirectCast(sen der, System.Componen tModel.Backgrou ndWorker)
        >>
        >>
        >'What can I put here?
        >>
        >End Sub
        >
        Index = Array.IndexOf(M yWorker, sender)
        >
        >
        Armin

        Comment

        Working...