Thread Question
Posted
by Polaris
on Stack Overflow
See other posts from Stack Overflow
or by Polaris
Published on 2010-05-04T06:44:12Z
Indexed on
2010/05/04
6:48 UTC
Read the original article
Hit count: 219
I have method which create background thread to make some action. In this background thread I create object. But this object while creating in runtime give me an exception :
The calling thread must be STA, because many UI components require this.
I know that I must use Dispatcher to make reflect something to UI. But in this case I just create an object and dont iteract with UI. This is my code:
public void SomeMethod()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(Background_Method);
worker.RunWorkerAsync();
}
void Background_Method(object sender, DoWorkEventArgs e)
{
TreeView tv = new TreeView();
}
How can I create objects in background thread?
I use WPF application
© Stack Overflow or respective owner