TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Liviu Mihail
NA
1
0
How to add UIElement to UI on a separate thread in WPF?
Nov 21 2007 4:13 PM
What I want to do:
into a Grid, I want to add 2 UserControl's at runtime.
Every control can stop to respond to a user input at a time (on an action inside control). But in the same time, I want to be able to work with the second control.
For this, I think is needed to create every control on a separate thread.
When I want to add this controls to grid I receive this error:
"The calling thread cannot access this object because a different thread owns it."
this is my code:
private void function MainFunc()
{
//add first control to grid
NewPanelThread();
//add second to grid
NewPanelThread();
}
private void NewPanelThread()
{
Thread thre = new Thread(new ThreadStart(AddPanel));
thre.SetApartmentState(ApartmentState.STA);
thre.IsBackground = true;
thre.Start();
}
private void AddPanel()
{
UserControl dPanel = new UserControl ();
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new OneArgDelegate(UpdateUserInterface), dPanel);
System.Windows.Threading.Dispatcher.Run();
}
private delegate void OneArgDelegate(UserControl myControl);
private void UpdateUserInterface(UserControl objPanel)
{
MyGrid.Children.Add(objPanel);
}
Reply
Answers (
0
)
Threading: Help needed Want to suspend and resume the loop function in the thread for every 100 lines of read in csv file
How to use Terminal Services API to log into a system