473,464 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'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 9848
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,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.