on 04-29-2005 5:34 PM
Hi,
I'm using OCX components in VB.Net,to connect to SAP and call BAPIs or ABAP functions,just like in VB(because I don't know how to use .Net Connect).Now I have the problems as described following:
When I test my project in a VB.Net windows form,it works very well.The test code(test no.1):
<b> Dim ojob As SAPJobInventory
ojob = New SAPJobInventory
ojob.Start()</b>
But when I create a new thread to run this code,the error occurs.The test code(test no.2):
<b> Dim ojob As SAPJobInventory
Dim othr As ThreadStart, o As Thread
ojob = New SAPJobInventory
othr = New ThreadStart(AddressOf ojob.Start)
o = New Thread(othr)
o.Start()</b>
The error raised at the second line in the code below:
<b>oSAPFunction = CreateObject("SAP.Functions")
oSAPFunction.Connection = oSAPConnection</b>
I have set logon parameters to oSAPConnection and call the Logon method successfully,and <b>the same code excecute correctly in test No.1,but error in test No.2</b>
The detail error message is:
err.Number:458
err.Description:Bad variant type
err.Source:wdtaocx
Could anybody have any ideas about it,or have ever met the problem just like so,or could give me some suggestions?
Thanks very much!
Best Regards.
Richie
Message was edited by: cloud yin
Message was edited by: cloud yin
Message was edited by: cloud yin
Message was edited by: cloud yin
Hello,
An ActiveX control must be run in an STA apartment. Because the attribute [STAThread] is applied to the Main method of a WinForm class by default with a WinForms Project, the main thread of your app will run in STA mode. This is why your test no.1 works. However, if you want to use the ActiveX Controls in a programatically created thread, you need to set the thread to STA mode manually before you starting the thread:
o = New Thread(othr)
o.ApartmentState = System.Threading.ApartmentState.STA
o.Start()
Hope it helps,
Guangwei
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.