|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
'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) 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 Show quoteHide quote "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> wrote in message news:O5HvsJVcGHA.3344@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) > > "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: Which exception? Please post the complete exception information.> I'm getting an unhandled exception error on the below: -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:OcSGTpWcGHA.636@TK2MSFTNGP05.phx.gbl... > "Adam Honek" <AdamHo***@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/> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: Does your 'Sub Main' have the 'MTAThread' attribute specified? If this is > 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. 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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:OXg7iDccGHA.636@TK2MSFTNGP05.phx.gbl... > "Adam Honek" <AdamHo***@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/> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: Hmmm... You can add Windows XP Visual Styles as follows:> 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. \\\ 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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:OsEgpbgcGHA.1276@TK2MSFTNGP03.phx.gbl... > "Adam Honek" <AdamHo***@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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:OcSGTpWcGHA.636@TK2MSFTNGP05.phx.gbl... > "Adam Honek" <AdamHo***@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/> |
|||||||||||||||||||||||