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 / Languages / VB.NET / May 2006

Tip: Looking for answers? Try searching our database.

'OpenFileDialog crashes for no reason?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adam Honek - 06 May 2006 22:17 GMT
This really is my unlucky day it seems.

I'm getting an unhandled exception error on the below:

I've changed it without the Me and not a chance, still crashes the app.

All I want to do is get a file name hence file path of a selected file.

Thanks,
Adam

'OpenFileDialog1.InitialDirectory = Application.StartupPath

'OpenFileDialog1.ShowDialog(Me)
Adam Honek - 07 May 2006 00:21 GMT
I don't get the bug with FontDialog1.ShowDialog()

This leads me to think it's something that I haven't initialized the
'OpenFileDialog1 before showing it????

Can't think of anything else at the moment.

Adam

> This really is my unlucky day it seems.
>
[quoted text clipped - 10 lines]
>
> 'OpenFileDialog1.ShowDialog(Me)
Herfried K. Wagner [MVP] - 07 May 2006 01:08 GMT
"Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
> I'm getting an unhandled exception error on the below:

Which exception?  Please post the complete exception information.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

Adam Honek - 07 May 2006 02:00 GMT
This is the error it tells me:

An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in System.Windows.Forms.dll

Additional information: 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.

All item dialogs word (ie color, font). All in the same thread too.

Adam

> "Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
>> I'm getting an unhandled exception error on the below:
>
> Which exception?  Please post the complete exception information.
Herfried K. Wagner [MVP] - 07 May 2006 11:27 GMT
"Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
> An unhandled exception of type 'System.Threading.ThreadStateException'
> occurred in System.Windows.Forms.dll
[quoted text clipped - 3 lines]
> function has STAThreadAttribute marked on it. This exception is only
> raised if a debugger is attached to the process.

Does your 'Sub Main' have the 'MTAThread' attribute specified?  If this is
the case, either remove the attribute or change it to 'STAThread'.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

Adam Honek - 07 May 2006 17:13 GMT
My app doesn't start in Sub Main() but rather frmMain_Load().

If I change it all the eye candy Windows XP GUI features get
disabled hence I keep it on.

Adam

> "Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
>> An unhandled exception of type 'System.Threading.ThreadStateException'
[quoted text clipped - 7 lines]
> Does your 'Sub Main' have the 'MTAThread' attribute specified?  If this is
> the case, either remove the attribute or change it to 'STAThread'.
Herfried K. Wagner [MVP] - 07 May 2006 19:49 GMT
"Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
> My app doesn't start in Sub Main() but rather frmMain_Load().
>
> If I change it all the eye candy Windows XP GUI features get
> disabled hence I keep it on.

Hmmm...  You can add Windows XP Visual Styles as follows:

\\\
Application.EnableVisualStyles()
Application.Run(New MainForm())
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

Adam Honek - 07 May 2006 23:26 GMT
I'll try this later on in the evening.

I'm sure all MS dialog controls use inheritance hence the openfiledialog
must be a version of say fontdialog etc.

Do you think entering a critical section is something  that might be viable?

It's obviously a thread error that manifests itself if openfiledialog is not
called from the main app's thread.

Do others get the same bug, a simply new project with a 2nd thread should be
enough to test it out?

VS 2005 here.

Adam

> "Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
>> My app doesn't start in Sub Main() but rather frmMain_Load().
[quoted text clipped - 8 lines]
> Application.Run(New MainForm())
> ///
Adam Honek - 07 May 2006 04:39 GMT
I checked in my other forms and in the main form it doesn't crash.

OpenFileDialog1.ShowDialog()

As others are in there own threads this leads me to believe it's something
to do with threading.

Still don't get why the ColorDialog and FontDialog all work fine in ALL
forms threaded or not but this one just refuses to listen.

Very puzzling.

What else can I do? Is this a bug, seems a pretty severe one, OpenDialog is
a very often used control.

Thanks,
Adam

> "Adam Honek" <AdamHonek@Webmaster2001.freeserve.co.uk> schrieb:
>> I'm getting an unhandled exception error on the below:
>
> Which exception?  Please post the complete exception information.

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.