problem regarding threads, invoke and class libraries

T

ThunderMusic

Hi,
I have a class library with some classes... One of those classes fire
events from a different thread. When I try to display the information
contained in the event args of this event in my UI, it says I can't access
my control's properties from a different thread... I wanted to use the
Invoke() method, but it's not available in my class nor in my thread... What
is the solution to this? I mean, how can I raise events like all others do,
in-proc with the form's thread?

thanks

ThunderMusic
 
J

Jon Skeet [C# MVP]

ThunderMusic said:
I have a class library with some classes... One of those classes fire
events from a different thread. When I try to display the information
contained in the event args of this event in my UI, it says I can't access
my control's properties from a different thread... I wanted to use the
Invoke() method, but it's not available in my class nor in my thread... What
is the solution to this? I mean, how can I raise events like all others do,
in-proc with the form's thread?

You need to call Invoke on a UI element. (Or anything else implementing
ISynchronizeInvoke appropriately.)

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml for more
information.
 
T

ThunderMusic

I'm actually not using any form in my class library, so I don't want users
of the library to call invoke on their controls each time they receive the
events... anyway, I just found the solution... I found it there :

http://www.codeproject.com/csharp/invoke_other_way.asp

it's at about half of the page...

I hope it can help someone else... ;)

Thanks for the quick answer tought...

ThunderMusic
 

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