I have 2 objects. Foo and Bar in two different threads. Now I want to raise an event in Foo but in the thread of Bar.
and how can I use SynchronizationContext.Current for that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Neither "Foo" nor "Bar" really have threads… you would need an external message-pump mechanism to push messages between threads, such as is provided in winforms (Control.Invoke) and WPF (Dispatcher). Alternatively, something like a (synchronized) producer/consumer queue would suffice if you don’t mind one of the threads being devoted to waiting (passively) for messages.
Unless you have written your own sync-context, it is impossible for us to say what
SynchronizationContext.Currentwill be; in many cases it isnull.Can you add more context to the problem?