Home All Groups Group Topic Archive Search About

Callback from a thread

Author
22 Feb 2006 9:55 PM
sidprice
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.

Author
22 Feb 2006 10:45 PM
TrtnJohn
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.

Show quoteHide quote
"sidpr***@softtools.com" wrote:

> 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.
>
>
>
Author
23 Feb 2006 4:05 AM
Michael D. Ober
In VS 2005, take a look at the Background worker class.

Mike Ober.

Show quoteHide quote
"TrtnJohn" <TrtnJ***@discussions.microsoft.com> wrote in message
news:E8BFC060-303C-4018-A0E4-5677025628F8@microsoft.com...
> 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.
>
> "sidpr***@softtools.com" wrote:
>
> > 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.
> >
> >
> >
>
Author
23 Feb 2006 4:44 AM
sidprice
Thanks, however I am working with VS 2003.

sid.

Show quoteHide quote
"Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message
news:NvaLf.59$6I.32@newsread3.news.pas.earthlink.net...
> In VS 2005, take a look at the Background worker class.
>
> Mike Ober.
>
> "TrtnJohn" <TrtnJ***@discussions.microsoft.com> wrote in message
> news:E8BFC060-303C-4018-A0E4-5677025628F8@microsoft.com...
>> 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.
>>
>> "sidpr***@softtools.com" wrote:
>>
>> > 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.
>> >
>> >
>> >
>>
>
>
>
Author
23 Feb 2006 4:46 AM
sidprice
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.


Show quoteHide quote
"TrtnJohn" <TrtnJ***@discussions.microsoft.com> wrote in message
news:E8BFC060-303C-4018-A0E4-5677025628F8@microsoft.com...
> 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.
>
> "sidpr***@softtools.com" wrote:
>
>> 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.
>>
>>
>>