E
eBob.com
I have a multi-threaded app consisting of the UI thread and a number of
worker-bee threads. An enhancement which I'd like to make requires that the
worker-bee threads use FolderBrowserDialog. But the FolderBrowserDialog
form which appears has no "tree" for selecting the folder. My hours and
hours and hours of research indicate that this is a well known problem which
relates to the Apartment Mode/Mood/View/Model/Feng Shui/Whatever and the
allegation that the FolderBrowserDialog uses ActiveX. I've been able to
determine that if I tell my app not to create worker-bee threads but to do
all of the work on the UI thread the FolderBrowserDialog displays correctly.
I'm bleary eyed from all of the reading I've been doing but I think I recall
someone reporting that setting the Apartment Model for the worker-bee
threads can fix my problem. But I haven't come across any documented way of
doing that which works (see below). One of my problems maybe is that I
don't explicitly create the worker-bee threads. They seem to come about
because of the BeginInvoke method of a Delegate.
My first attemp to set the Apartment Model for the worker-bee threads was
this ...
Thread.CurrentThread.ApartmentState = ApartmentState.STA
.... but IntelliSense claims that something about this has been denigrated.
So than I tried ...
Thread.CurrentThread.SetApartmentState(ApartmentState.STA)
.... but that throws an InvalidOperationException.
I think I also read that there is a Project Property setting which allows
you to specify the Apartment Model of any created threads but I am unable to
find it in VBE 2008.
If I do manage to get the worker-bee threads running in Apartment Model STA
will I than have problems with the Excel COM interface which I use to create
a spreadsheet? (Some of the posts I've found say that this Apartment Model
stuff relates to COM.)
I hope someone can help me with this because I haven't experienced so much
misery with VB.Net in a long time.
Thanks, Bob
worker-bee threads. An enhancement which I'd like to make requires that the
worker-bee threads use FolderBrowserDialog. But the FolderBrowserDialog
form which appears has no "tree" for selecting the folder. My hours and
hours and hours of research indicate that this is a well known problem which
relates to the Apartment Mode/Mood/View/Model/Feng Shui/Whatever and the
allegation that the FolderBrowserDialog uses ActiveX. I've been able to
determine that if I tell my app not to create worker-bee threads but to do
all of the work on the UI thread the FolderBrowserDialog displays correctly.
I'm bleary eyed from all of the reading I've been doing but I think I recall
someone reporting that setting the Apartment Model for the worker-bee
threads can fix my problem. But I haven't come across any documented way of
doing that which works (see below). One of my problems maybe is that I
don't explicitly create the worker-bee threads. They seem to come about
because of the BeginInvoke method of a Delegate.
My first attemp to set the Apartment Model for the worker-bee threads was
this ...
Thread.CurrentThread.ApartmentState = ApartmentState.STA
.... but IntelliSense claims that something about this has been denigrated.
So than I tried ...
Thread.CurrentThread.SetApartmentState(ApartmentState.STA)
.... but that throws an InvalidOperationException.
I think I also read that there is a Project Property setting which allows
you to specify the Apartment Model of any created threads but I am unable to
find it in VBE 2008.
If I do manage to get the worker-bee threads running in Apartment Model STA
will I than have problems with the Excel COM interface which I use to create
a spreadsheet? (Some of the posts I've found say that this Apartment Model
stuff relates to COM.)
I hope someone can help me with this because I haven't experienced so much
misery with VB.Net in a long time.
Thanks, Bob