problem with calling folderbrowingDialog in a child thread.
-
in a child thread i'm calling folderbrowsing dialog , i get the exceptiuon and , i got some articles saying i must use STAThreadAttribute attribute for the main method , i did that and the result was the same "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." i tried
inthrd.SetApartmentState(System.Threading.ApartmentState.STA);
too but still the same result. can any one have any idea about this. thanx in advance.
-
in a child thread i'm calling folderbrowsing dialog , i get the exceptiuon and , i got some articles saying i must use STAThreadAttribute attribute for the main method , i did that and the result was the same "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." i tried
inthrd.SetApartmentState(System.Threading.ApartmentState.STA);
too but still the same result. can any one have any idea about this. thanx in advance.
I don't know all the details, however here are some facts: 1. you can set the apartment state only once; 2. IIRC you can't set it at all on ThreadPool threads; 3. I don't recall what happens if you try and ignore #1 or #2. 4. the easiest way to solve such problems most often is to do all user interaction on the main (aka GUI) thread. BTW: when referring to some error message or exception you should paste it verbatim in your question. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3 -
I don't know all the details, however here are some facts: 1. you can set the apartment state only once; 2. IIRC you can't set it at all on ThreadPool threads; 3. I don't recall what happens if you try and ignore #1 or #2. 4. the easiest way to solve such problems most often is to do all user interaction on the main (aka GUI) thread. BTW: when referring to some error message or exception you should paste it verbatim in your question. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3thanks,actually what i'm doing is creating a new window in the child thread, so in that window i want to open this folderbrowsingdialog, so at that point i get the exception. and following is the exception i got 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. thanks in advance.
-
thanks,actually what i'm doing is creating a new window in the child thread, so in that window i want to open this folderbrowsingdialog, so at that point i get the exception. and following is the exception i got 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. thanks in advance.
thanks again . i found the issue , i'm using a separate class for creating threads in the application , and i had set the
l_thrd.SetApartmentState(ApartmentState.STA);
out side that class , when i moved this line into that thread creating class i got my problem solved. but i really don't know difference the two places i used the code thankx .
-
thanks,actually what i'm doing is creating a new window in the child thread, so in that window i want to open this folderbrowsingdialog, so at that point i get the exception. and following is the exception i got 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. thanks in advance.
It is generally a bad idea to create UI on child threads, particularly if those threads are doing any data processing. The modal stack for different threads is separated, so (for example) message boxes and dialogs from a child thread won't interact as you expect with the main thread. A modal dialog is better than normal forms because you don't need to add a message pump to the thread but it's still not recommended in most situations. (For example, what if two threads want to ask the same question at the same time?) Have you thought about why you want to do this?
-
in a child thread i'm calling folderbrowsing dialog , i get the exceptiuon and , i got some articles saying i must use STAThreadAttribute attribute for the main method , i did that and the result was the same "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." i tried
inthrd.SetApartmentState(System.Threading.ApartmentState.STA);
too but still the same result. can any one have any idea about this. thanx in advance.