I have a window with a single button within.
The code-behind is
private void Button_Click(object sender, RoutedEventArgs e)
{
Trace.TraceInformation("Button ThreadId: {0}", Thread.CurrentThread.ManagedThreadId);
Thread w = new Thread((ThreadStart) Worker);
w.SetApartmentState(ApartmentState.STA); // removing/adding this doesn't make effect
w.Start();
MessageBox.Show("Direct");
}
void Worker()
{
Trace.TraceInformation("Worker ThreadId: {0}", Thread.CurrentThread.ManagedThreadId);
this.Dispatcher.Invoke((Action)delegate
{
Trace.TraceInformation("Invoked ThreadId: {0}", Thread.CurrentThread.ManagedThreadId);
MessageBox.Show("Invoked");
});
}
Clicking the button results in 2 message boxes.
At the same time, trace shows same numbers for Button ThreadId and Invoked ThreadId.