Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2008

Tip: Looking for answers? Try searching our database.

OLE call STAThreadAttribute exeception on saveFileDialog.ShowDialog(this)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stefan - 20 Jan 2008 08:29 GMT
Hi,

although main() has [STAThread] attribute, somehow my C#/VS2005 win
form application changed to MTA mode. Within the application I create
a backgroud process that does the work to be able to update a progress
bar in the main window. After the backgroud process is completed
(backgroundWorker_RunWorkerCompleted was called), I want to write some
info to LOG-files. Upon calling saveFileDialog.ShowDialog(this) to get
a filename, I get the STAThreadAttribute exception. Just before this
call I checked System.Threading.Thread.CurrentThread.ApartmentState
which is then  MTA.

So my questions are:
- what makes my application switch to MTA
- what can I do to bring it back to STA
- why this OLE call

Thanks in advance for any hints!
Stefan

P.S.: This is a repost from
microsoft.public.dotnet.framework.windowsforms
Amar - 26 Jan 2008 03:09 GMT
> Hi,
>
[quoted text clipped - 18 lines]
> P.S.: This is a repost from
> microsoft.public.dotnet.framework.windowsforms

You could do the easier thing and change the attribute to STA..
OR..

Spawn a new thread to do the file writing. BE carefull to place the
STA attrbute on the method you pass as the thread start.
this will solve your problem.

As for your question..
My theory is that .net uses legacy components for file dialog and save
dialog.
Stefan - 31 Jan 2008 10:17 GMT
Thanks for your feedback.

I already tried to change back to STA. This does not work.

As my app is still under development it never occured to me to test
the thing as an EXE. There the problem does not exist. It's just when
I run/debug the app within VS IDE. If I disable the debug option "VS
host process" in the app's settings, then it also runs without
exception in the IDE (but then I cannot debug it).

I also found postings about [STAThread] not working (guess this was
correct for older versions of .NET) and the advice to set STA-mode as
the first statement in the main method. All this won't work. The app
is by then already in MTA mode and you just can't change to STA mode
by simply calling SetAppartmentState.

Stefan

> > Hi,
>
[quoted text clipped - 31 lines]
>
> - Zitierten Text anzeigen -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.