473,133 Members | 2,185 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,133 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 9778
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
3
by: jimatqsi | last post by:
So, I had this bright idea today that didn't quite work out. Or maybe it is working out but requires me to change a habit. I'm working on a form that will be a sub-form of another form. During...
0
by: saichinnu1852 | last post by:
I am trying to use Collibra by installing it using AWS Marketplace AMI that they offer and launched the EC2 instance. However, when I try to login to Collibra using the IP Address of the EC2 instance...

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.