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 :
To make your code simply work, you must join a STA COM
apartment by calling Thread.SetApartmentState(ApartmentState.STA)
. Since BackgroundWorker
is probably using some shared thread pool, joining a particular apartment may affect other users of this thread pool or may even fail if it has already been set to e.g. MTA
before. Even if it all worked out, your newly created TreeView
would be locked to this worker thread. You wouldn't be able to use it in your main UI thread.
If you explained in a bit more detail about your true intentions, you would surely get better help.