473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

'OpenFileDialog crashes for no reason?

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)
May 6 '06 #1
8 9820
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
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
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)

May 6 '06 #2
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
I'm getting an unhandled exception error on the below:


Which exception? Please post the complete exception information.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 7 '06 #3
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oc*************@TK2MSFTNGP05.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
I'm getting an unhandled exception error on the below:


Which exception? Please post the complete exception information.

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

May 7 '06 #4
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


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oc*************@TK2MSFTNGP05.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
I'm getting an unhandled exception error on the below:


Which exception? Please post the complete exception information.

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

May 7 '06 #5
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
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.


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

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

May 7 '06 #6
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OX*************@TK2MSFTNGP05.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
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.


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

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

May 7 '06 #7
"Adam Honek" <Ad*******@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())
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 7 '06 #8
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...
"Adam Honek" <Ad*******@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())
///

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

May 7 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: violin wang | last post by:
hi I wrote a windows based program.The main UI named form_base has a button "btn1".In btn1`s click event handler I used ShowDialog(this) to show another form named form_test.form_test also has a...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
4
by: hullnwm | last post by:
In my asp.net page I'm attempting to use the OpenfileDialog object to offer a common dialog box for the user to select a particular file on their hard drive that may subsequently be uploaded to...
0
by: Phil | last post by:
Can somebody direct me a site or elsewhere where I could get hold of some source code for the OpenFileDialog used in VB.net? The reason I want it is that I'm trying to write my own file/folder...
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
2
by: dermot | last post by:
hi, I'm opening a file dialog in a vb.net form. I want to show only files modified after a certain date. Is there anyway to filter for this? Thanks
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
7
by: Adam Honek | last post by:
Given I have problems with using OpenFileDialog as explained in another thread here, what other options are there? All I need is for the user to be able to browse for files and select one or...
3
by: aagarwal8 | last post by:
Hi, When the OpenFileDialog is opened on one of my forms, i can trigger the close of the second form from my primary form. (Plz note, both the forms are running on different threads). However,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.