Threading

L

Lou

I have a project with a COM class.
It creates a new thread whose function loops continually.
Within the looping function I Raise an event.
When the client app (VB6) receives the event, what thread does it receive it
on and is this thread safe.
Is there a better way to raise an event from the .NET class thats on a
different thread.

-Lou
 
M

Mattias Sjögren

When the client app (VB6) receives the event, what thread does it receive it
on and is this thread safe.

Events are just like regular method calls. They are handled on the
same thread that they are raised on.

Is there a better way to raise an event from the .NET class thats on a
different thread.

Better in what way?


Mattias
 
L

Lou

So how should I do this?
Is it safe to do it the way I am doing it?
My VB6 client keeps crashing in the IDE. I think it's this threading issue.
The .NET object Event gets raised on a different thread than the client app
that receives it, won't this cause problems?
If so what is the correct method?

Thanks
Louie
 
A

Armin Zingler

Lou said:
So how should I do this?
Is it safe to do it the way I am doing it?
My VB6 client keeps crashing in the IDE. I think it's this threading
issue. The .NET object Event gets raised on a different thread than
the client app that receives it, won't this cause problems?
If so what is the correct method?

I have not much experience in it, but what I would do in order to be on the
safe side, is:
Create a hidden window in the first thread. In the other thread, call the
Form's Invoke method to marshal the action back to the first thread. There
you can raise the event.
It's a hack but as VB6 does not really support free threading it can be a
work-around.


Armin
 

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