Invoking a tooltip from a secundary thread

T

Thijs

Hello everybody,

I´ve got a problem that´s slightly complicated (at least to me it
seems) so I will try to state it as clearly as possible.

At a certain point in time, I start a second thread that runs one of
my functions. The function in this second raises events. As you might
know, the eventhandler for this event is executed within this second
thread and not within the first. It´s not possible to update
properties of a user control (like a label) that was created in the
first thread, from a second thread. Now .NET has this neat little
invoke() method on their controls, so that you can still use delegates
to update these controls.

So far so good.

However, I run into problems with one special object: a ToolTip
instance. I want the eventhandler, executed by the second thread, to
display a tooltip. However, there is no invoke() method on the
tooltip, and that makes invoking it quite hard. Calling it directly
doesn´t work either.

Does anyone have a solution for this so that I can still show this
tooltip?

Kind regards,
Thijs Brilleman
 
P

Patrice

You could :
- configure the tooltip so that it is displayed automatically when hovering
the control if applicable
- if you want to display explicitely the tool tip, you can use whatever
Invoke method is available. AFAIK having Invoke on all controls is a
convenience to avoid going always to the parent form but calling invoke on
any control that belongs to the form (or the Form.Invoke method) will always
call on the same UI thread...

--
Patrice

"Thijs" <[email protected]> a écrit dans le message de (e-mail address removed)...
Hello everybody,

I´ve got a problem that´s slightly complicated (at least to me it
seems) so I will try to state it as clearly as possible.

At a certain point in time, I start a second thread that runs one of
my functions. The function in this second raises events. As you might
know, the eventhandler for this event is executed within this second
thread and not within the first. It´s not possible to update
properties of a user control (like a label) that was created in the
first thread, from a second thread. Now .NET has this neat little
invoke() method on their controls, so that you can still use delegates
to update these controls.

So far so good.

However, I run into problems with one special object: a ToolTip
instance. I want the eventhandler, executed by the second thread, to
display a tooltip. However, there is no invoke() method on the
tooltip, and that makes invoking it quite hard. Calling it directly
doesn´t work either.

Does anyone have a solution for this so that I can still show this
tooltip?

Kind regards,
Thijs Brilleman
 
M

Michel Posseth [MCP]

Hello Thijs ,

You can just use invokerequired and if returned true use a delegate to
synchronize

i wrote some examples for this newsgroup in the past

1.
http://groups.google.nl/group/micro...=st&q=invokerequired+posseth#3ef6641d3bedd548
2.
http://groups.google.nl/group/micro...=st&q=invokerequired+posseth#8a2b4d3823041f08
3.
http://groups.google.nl/group/micro...=st&q=invokerequired+posseth#476308ddc6048859


Wit the examples i show above it should be easy to acomplish what you want ,

HTH

Michel Posseth [MCP]



"Thijs" <[email protected]> schreef in bericht
Hello everybody,

I´ve got a problem that´s slightly complicated (at least to me it
seems) so I will try to state it as clearly as possible.

At a certain point in time, I start a second thread that runs one of
my functions. The function in this second raises events. As you might
know, the eventhandler for this event is executed within this second
thread and not within the first. It´s not possible to update
properties of a user control (like a label) that was created in the
first thread, from a second thread. Now .NET has this neat little
invoke() method on their controls, so that you can still use delegates
to update these controls.

So far so good.

However, I run into problems with one special object: a ToolTip
instance. I want the eventhandler, executed by the second thread, to
display a tooltip. However, there is no invoke() method on the
tooltip, and that makes invoking it quite hard. Calling it directly
doesn´t work either.

Does anyone have a solution for this so that I can still show this
tooltip?

Kind regards,
Thijs Brilleman
 
T

Thijs

Both of you, thanks a lot. The simple solution Patrice offered turned
out to be very effective.

Thijs
 

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

Top