Callback from a thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    Callback from a thread

    Hello,

    I have a worker thread ( a shared method in a class) that needs to callback
    to another (monitoring) class on certain events. I have been unable to
    figure out how to pass the callback address of a delegate in the monitoring
    class to the thread. Could someone please point me to a sample or give a few
    clues. I have tried to use TLS but can't figure out how to send the result
    of the "address of" operator and then recover it by using SetData and
    GetData.

    Thanks,
    Sid.


  • TrtnJohn

    #2
    RE: Callback from a thread

    Threads can Raise Events. Just be aware that the event handler in the
    monitoring class will be running in the secondary thread so it should only do
    thread-safe operations. If you need to access UI elements from the secondary
    thread or in the event handler, you will need to marshal the call back to the
    UI thread using the Control.Invoke method of the UI element you wish to
    update.

    "sidprice@softt ools.com" wrote:
    [color=blue]
    > Hello,
    >
    > I have a worker thread ( a shared method in a class) that needs to callback
    > to another (monitoring) class on certain events. I have been unable to
    > figure out how to pass the callback address of a delegate in the monitoring
    > class to the thread. Could someone please point me to a sample or give a few
    > clues. I have tried to use TLS but can't figure out how to send the result
    > of the "address of" operator and then recover it by using SetData and
    > GetData.
    >
    > Thanks,
    > Sid.
    >
    >
    >[/color]

    Comment

    • Michael D. Ober

      #3
      Re: Callback from a thread

      In VS 2005, take a look at the Background worker class.

      Mike Ober.

      "TrtnJohn" <TrtnJohn@discu ssions.microsof t.com> wrote in message
      news:E8BFC060-303C-4018-A0E4-5677025628F8@mi crosoft.com...[color=blue]
      > Threads can Raise Events. Just be aware that the event handler in the
      > monitoring class will be running in the secondary thread so it should only[/color]
      do[color=blue]
      > thread-safe operations. If you need to access UI elements from the[/color]
      secondary[color=blue]
      > thread or in the event handler, you will need to marshal the call back to[/color]
      the[color=blue]
      > UI thread using the Control.Invoke method of the UI element you wish to
      > update.
      >
      > "sidprice@softt ools.com" wrote:
      >[color=green]
      > > Hello,
      > >
      > > I have a worker thread ( a shared method in a class) that needs to[/color][/color]
      callback[color=blue][color=green]
      > > to another (monitoring) class on certain events. I have been unable to
      > > figure out how to pass the callback address of a delegate in the[/color][/color]
      monitoring[color=blue][color=green]
      > > class to the thread. Could someone please point me to a sample or give a[/color][/color]
      few[color=blue][color=green]
      > > clues. I have tried to use TLS but can't figure out how to send the[/color][/color]
      result[color=blue][color=green]
      > > of the "address of" operator and then recover it by using SetData and
      > > GetData.
      > >
      > > Thanks,
      > > Sid.
      > >
      > >
      > >[/color]
      >[/color]



      Comment

      • Guest's Avatar

        #4
        Re: Callback from a thread

        Thanks, however I am working with VS 2003.

        sid.

        "Michael D. Ober" <obermd.@.alum. mit.edu.nospam> wrote in message
        news:NvaLf.59$6 I.32@newsread3. news.pas.earthl ink.net...[color=blue]
        > In VS 2005, take a look at the Background worker class.
        >
        > Mike Ober.
        >
        > "TrtnJohn" <TrtnJohn@discu ssions.microsof t.com> wrote in message
        > news:E8BFC060-303C-4018-A0E4-5677025628F8@mi crosoft.com...[color=green]
        >> Threads can Raise Events. Just be aware that the event handler in the
        >> monitoring class will be running in the secondary thread so it should
        >> only[/color]
        > do[color=green]
        >> thread-safe operations. If you need to access UI elements from the[/color]
        > secondary[color=green]
        >> thread or in the event handler, you will need to marshal the call back to[/color]
        > the[color=green]
        >> UI thread using the Control.Invoke method of the UI element you wish to
        >> update.
        >>
        >> "sidprice@softt ools.com" wrote:
        >>[color=darkred]
        >> > Hello,
        >> >
        >> > I have a worker thread ( a shared method in a class) that needs to[/color][/color]
        > callback[color=green][color=darkred]
        >> > to another (monitoring) class on certain events. I have been unable to
        >> > figure out how to pass the callback address of a delegate in the[/color][/color]
        > monitoring[color=green][color=darkred]
        >> > class to the thread. Could someone please point me to a sample or give
        >> > a[/color][/color]
        > few[color=green][color=darkred]
        >> > clues. I have tried to use TLS but can't figure out how to send the[/color][/color]
        > result[color=green][color=darkred]
        >> > of the "address of" operator and then recover it by using SetData and
        >> > GetData.
        >> >
        >> > Thanks,
        >> > Sid.
        >> >
        >> >
        >> >[/color]
        >>[/color]
        >
        >
        >[/color]


        Comment

        • Guest's Avatar

          #5
          Re: Callback from a thread

          The thread is a shared method and to resolve this issue I have added a
          shared variable that holds the callback address. In the design of my
          application this works just fine since there is only a single thread
          instance running at once.

          Thanks to those who replied,
          Sid.


          "TrtnJohn" <TrtnJohn@discu ssions.microsof t.com> wrote in message
          news:E8BFC060-303C-4018-A0E4-5677025628F8@mi crosoft.com...[color=blue]
          > Threads can Raise Events. Just be aware that the event handler in the
          > monitoring class will be running in the secondary thread so it should only
          > do
          > thread-safe operations. If you need to access UI elements from the
          > secondary
          > thread or in the event handler, you will need to marshal the call back to
          > the
          > UI thread using the Control.Invoke method of the UI element you wish to
          > update.
          >
          > "sidprice@softt ools.com" wrote:
          >[color=green]
          >> Hello,
          >>
          >> I have a worker thread ( a shared method in a class) that needs to
          >> callback
          >> to another (monitoring) class on certain events. I have been unable to
          >> figure out how to pass the callback address of a delegate in the
          >> monitoring
          >> class to the thread. Could someone please point me to a sample or give a
          >> few
          >> clues. I have tried to use TLS but can't figure out how to send the
          >> result
          >> of the "address of" operator and then recover it by using SetData and
          >> GetData.
          >>
          >> Thanks,
          >> Sid.
          >>
          >>
          >>[/color][/color]


          Comment

          Working...