473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Open a folderbrowser from a thread - possible?

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
2 1278
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marco Nicosia | last post by:
Hello gang, My coworker and I are writing a Python class for the other developers within our team. This class is supposed to encapsulate several things, including daemonizing, setting up...
3
by: Mantorok | last post by:
Hi all Have 2 perculiar problems at the moment: 1) SpecialFolder enum is not being picked up in Intelli-sense (but it is compiling ok when I use this enum) 2) FolderBrowser displays an...
0
by: Nicklas | last post by:
Hi I need to open a folder window with a path decided by me. Eg. "C:\strangeFolder\myown". I.e. NOT a predefined folder defined by FolderId (e.g. MyDocuments, Printers etc.) I haven't managed...
3
by: MAF | last post by:
Does anyone know how to set a specific path for the FolderBrowser object? here is my existing code. private FolderBrowserDialog m_fb = new FolderBrowserDialog(); private DialogResult...
9
by: Amit D.Shinde | last post by:
How to enable user for selecting only folders and not the files with the Open File Dialog. i.e. I want only path of the selected folder is to be returned by Open File Dialog. i.e Open File Dialog...
4
by: MC D | last post by:
What's the best way to have a modal dialog that will only allow the selection of a FOLDER, rather than a file? Is there a property of the openFileDialog I'm missing, or is there another control...
2
by: jeff | last post by:
dear all, i am using .net 1.0 which don't have the .selectedpath property in FolderBrowser in VB.net . any hint to do it ? thanks.
2
by: TarheelsFan | last post by:
I was trying to convert a VB project that contained the class FolderBrowser to C#. I have added a reference to System.Design, and the FolderBrowser class now shows up, but when I call ...
1
by: Sheth Raxit | last post by:
even thred is not part of C-std, i feel its most relavant to comp.lang.c hope it will not off-topic ------- I am having data/or Text file, which is only used for reading by multiplethreads in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.