【发布时间】:2016-09-09 10:51:03
【问题描述】:
这是我表单中的new 方法:
Public Sub New(ByVal ConnectionString As String, ByVal ConSql As SqlClient.SqlConnection, ByVal Daman As Array, ByVal SDate As Integer, ByVal FDate As Integer)
Threading.Thread.CurrentThread.TrySetApartmentState(Threading.ApartmentState.STA)
' This call is required by the Windows Form Designer.
'Error Appear in this line
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Sto_TypeFormFrameTableAdapter.Connection.ConnectionString = ConnectionString
Me.Sto_typeformTableAdapter.Connection.ConnectionString = ConnectionString
con = ConSql
com.Connection = con
ConNew = ConnectionString
DamaneCod = Daman
Start = SDate
Final = FDate
Fill()
End Sub
当我创建表单的新对象时,InitializeComponent 命令出错。
错误信息是:
当前线程必须设置为单线程单元 (STA) 模式 在可以进行 OLE 调用之前。确保您的 Main 函数具有 STAThreadAttribute 标记就可以了。
此表单在一个项目中,其输出是另一个项目的 DLL 文件,并且在使用此 DLL 文件的另一个项目中不会出现错误。 我该如何解决?
【问题讨论】:
-
不要在 New 过程中做那些事情。