|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Current thread must be set to single thread apartment (STA)I have just upgraded a vb.net 2003 project to 2005. I get an error when trying to access a FolderBrowserDialog as follows Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click FolderBrowserDialog1.Description = "Please select a location for your web pages." 'Default to the c drive if it exists If Directory.Exists("c:\") = True Then FolderBrowserDialog1.SelectedPath = "c:\" Else FolderBrowserDialog1.SelectedPath = "" End If FolderBrowserDialog1.ShowDialog() end sub The error I get is: "the 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." So i created a class 'clsStartup' containing a main procedure: Public Class clsStartup <STAThread()> _ Shared Sub Main() ' Declare a variable named frm1 of type Form1. Dim frm1 As frmWSGWebSiteLocationUpdate ' Instantiate (create) a new Form1 object and assign ' it to variable frm1. frm1 = New frmWSGWebSiteLocationUpdate() ' Call the Application class' Run method ' passing it the Form1 object created above. Application.Run(frmWSGWebSiteLocationUpdate) End Sub End Class And set the startup object to be clsStartup. But I still get the same message. Can anyone help me please? Regards, Steve. Also tried using the <STAThreadAttribute()> with same result.
Public Class clsWSGStartup <STAThreadAttribute()> _ Shared Sub Main() ' Declare a variable named frm1 of type Form1. Dim frm1 As frmWSGWebSiteLocationUpdate frm1 = New frmWSGWebSiteLocationUpdate() Application.Run(frm1) End Sub End Class Regards, Steve. Show quoteHide quote "Steve Bugden" wrote: > Hi > > I have just upgraded a vb.net 2003 project to 2005. I get an error when > trying to access a FolderBrowserDialog as follows > > Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > FolderBrowserDialog1.Description = "Please select a location for > your web pages." > > 'Default to the c drive if it exists > If Directory.Exists("c:\") = True Then > FolderBrowserDialog1.SelectedPath = "c:\" > Else > FolderBrowserDialog1.SelectedPath = "" > End If > > FolderBrowserDialog1.ShowDialog() > > end sub > > The error I get is: > "the 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." > > So i created a class 'clsStartup' containing a main procedure: > > Public Class clsStartup > > <STAThread()> _ > Shared Sub Main() > > ' Declare a variable named frm1 of type Form1. > Dim frm1 As frmWSGWebSiteLocationUpdate > > ' Instantiate (create) a new Form1 object and assign > > ' it to variable frm1. > > frm1 = New frmWSGWebSiteLocationUpdate() > > ' Call the Application class' Run method > > ' passing it the Form1 object created above. > > Application.Run(frmWSGWebSiteLocationUpdate) > > End Sub > > End Class > > And set the startup object to be clsStartup. > > But I still get the same message. > > Can anyone help me please? > > Regards, > > Steve. I finally found the cause of the problem for anyone who might be interested.
I removed an out of date dll stored in bin\temp directory. THis dll was not referenced by the project, so I have no idea why it should cause a problem. Steve Show quoteHide quote "Steve Bugden" wrote: > Also tried using the <STAThreadAttribute()> with same result. > > Public Class clsWSGStartup > > <STAThreadAttribute()> _ > Shared Sub Main() > > ' Declare a variable named frm1 of type Form1. > Dim frm1 As frmWSGWebSiteLocationUpdate > frm1 = New frmWSGWebSiteLocationUpdate() > Application.Run(frm1) > > End Sub > > End Class > > Regards, > > Steve. > > "Steve Bugden" wrote: > > > Hi > > > > I have just upgraded a vb.net 2003 project to 2005. I get an error when > > trying to access a FolderBrowserDialog as follows > > > > Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > > > FolderBrowserDialog1.Description = "Please select a location for > > your web pages." > > > > 'Default to the c drive if it exists > > If Directory.Exists("c:\") = True Then > > FolderBrowserDialog1.SelectedPath = "c:\" > > Else > > FolderBrowserDialog1.SelectedPath = "" > > End If > > > > FolderBrowserDialog1.ShowDialog() > > > > end sub > > > > The error I get is: > > "the 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." > > > > So i created a class 'clsStartup' containing a main procedure: > > > > Public Class clsStartup > > > > <STAThread()> _ > > Shared Sub Main() > > > > ' Declare a variable named frm1 of type Form1. > > Dim frm1 As frmWSGWebSiteLocationUpdate > > > > ' Instantiate (create) a new Form1 object and assign > > > > ' it to variable frm1. > > > > frm1 = New frmWSGWebSiteLocationUpdate() > > > > ' Call the Application class' Run method > > > > ' passing it the Form1 object created above. > > > > Application.Run(frmWSGWebSiteLocationUpdate) > > > > End Sub > > > > End Class > > > > And set the startup object to be clsStartup. > > > > But I still get the same message. > > > > Can anyone help me please? > > > > Regards, > > > > Steve.
Visual Styles For Toolbar
using listview What is this? Opening a new form V1.1.4322 is being requested after I updated ATI catalyst Reportviewer: how to display different reports in same viewer Minimized parent mdi form not properly restored MDI child forms, if one maximizes, all maximize? iterating through forms collection in .net Tabbed interface |
|||||||||||||||||||||||