| Button button; private void Window_Loaded(object sender, RoutedEventArgs e) { var threadstart = new Thread(new ThreadStart(Create)); threadstart.SetApartmentState(ApartmentState.STA); threadstart.Start(); threadstart.Join(); threadstart = new Thread(new ThreadStart(Attach)); threadstart.Start(); threadstart.Join(); } private void Create() { button = new Button(); button.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; button.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } private void Attach() { Dispatcher.BeginInvoke(new Action(() => { Canvas.SetTop(button, 0); <===== The calling thread cannot access this object because a different thread owns it. Canvas.SetLeft(button, 0); MyCanvas.Children.Add(button); })); } |
The calling thread cannot access this object because a diffe
Hi, I'm Mohsen. I have a bad problem in my code.Please help me for solve my problem.
mohsen hadaeghiPosted May 12, 2013, 3:32 PM
but in my code is run in Windows Form Application and it work.
for example I create one thread for create button and second thread must add button control in my form(with Invoke method). but in Windows Presentation Fundation it has one error. :(
Can you show me a another solution for solve my problem?
VulpesPosted May 10, 2013, 11:09 AM