By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Open a folderbrowser from a thread - possible?

P: n/a
Hi guys,

Since you helped me out the last time I needed - let me thank you for that
if I haven't already ;-) - I decided to call for your help yet again.

I'd like to be able to open a FolderBrowser instance from within a thread I
lauched, but I don't seem to be able to. It gives me this exception

Current thread must be set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it. This exception is only raised if a debugger is attached to the
process.

And points me to this MSDN page

http://msdn2.microsoft.com/en-us/library/ms241609.aspx

So... Is there any way I can accomplish this, or do I have to think of
another way?

Thanks!

Andre Nogueira
Feb 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Andre,
I'd like to be able to open a FolderBrowser instance from within a thread I
lauched
Why?

So... Is there any way I can accomplish this, or do I have to think of
another way?


It can certainly be done but you have to make the thread to run in STA
like the message says, bu setting its ApartmentState property.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 22 '06 #2

P: n/a
Hi,

Thank you for your reply.

The reason I need to open if from a new thread, is that my application is
plugin-enabled. When the user loads/enables a plugin, my application calls
the "SetUp()" function on the plugin - and this might envolve ask the user
to select a folder, show a windows form, and so on.
A workaround would be to call this function from within my program (ie
without actually opening a new thread)... But in the meantime I'll try to
solve this, if only to gain new knowledge :-)

I ended up doing what the message says and it did work, but now I get this
error message:

The CLR has been unable to transition from COM context 0x1b07f8 to COM
context 0x1b0a20 for 60 seconds. The thread that owns the destination
context/apartment is most likely either doing a non pumping wait or
processing a very long running operation without pumping Windows messages.
This situation generally has a negative performance impact and may even lead
to the application becoming non responsive or memory usage accumulating
continually over time. To avoid this problem, all single threaded apartment
(STA) threads should use pumping wait primitives (such as
CoWaitForMultipleHandles) and routinely pump messages during long running
operations.

I tried to Google it, but couldn't find anything I could use. I'll try to
search a bit more before I change my code to call the setup() function
before creating a thread...

Andre Nogueira

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ea****************@TK2MSFTNGP10.phx.gbl...
Andre,
I'd like to be able to open a FolderBrowser instance from within a thread
I
lauched


Why?

So... Is there any way I can accomplish this, or do I have to think of
another way?


It can certainly be done but you have to make the thread to run in STA
like the message says, bu setting its ApartmentState property.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Feb 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.