communicate from a background thread to the main

R

Ragid

Is there a way to communicate from a background thread to the main thread
and how?
Suppose the background is written in unmanaged C++, what would than be the
answer?
Regards
Ragid
 
A

Alberto Poblacion

Ragid said:
Suppose the background thread is implemented as a managed dll component.
Can
it stil use Invoke method to do the reqwired job?

If when you say "communicate from a background thread to the main thread"
you mean "pass some data from one thread to the other", then the simplest
way to do it would be to declare a public field or property in your managed
DLL, write values into it from one thread, and read its value from the other
thread. Of course, you will need some synchronization so that one thread
doesn't try to read the shared value while the other is in the middle of
writing. A simple lock(...) instruction should work, although you can use
any of the synchronization mechanisms available in .Net, such as an explicit
Mutex.
 
A

Alberto Poblacion

Ragid said:
Suppose the background thread is implemented as a managed dll component.
Can
it stil use Invoke method to do the reqwired job?

If when you say "communicate from a background thread to the main thread"
you mean "pass some data from one thread to the other", then the simplest
way to do it would be to declare a public field or property in your managed
DLL, write values into it from one thread, and read its value from the other
thread. Of course, you will need some synchronization so that one thread
doesn't try to read the shared value while the other is in the middle of
writing. A simple lock(...) instruction should work, although you can use
any of the synchronization mechanisms available in .Net, such as an explicit
Mutex.
 
R

Ragid

Thnaks Pete,
Suppose the background thread is implemented as a managed dll component. Can
it stil use Invoke method to do the reqwired job?
Regards
Ragid
 
R

Ragid

Thnaks Pete,
Suppose the background thread is implemented as a managed dll component. Can
it stil use Invoke method to do the reqwired job?
Regards
Ragid
 

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