communicate from a background thread to the main

  • Thread starter Thread starter Ragid
  • Start date Start date
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
 
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.
 
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.
 
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
 
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
 
Back
Top