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)
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)
"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.