以web形式对function module进行调用与form形式基本一样,唯一值得注意的地方就是:"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.".也就是说有些AcrtiveX控件或者Com组件必须运行在单线程单元下(STA:Single Thread Apartment ),否则的话会抛出“Bad variant type”异常。解决方案为:新开一个线程,并将该线程的运行模式设置为STA,然后再改线程下对Com组件或者ActiveX控件进行调用。
protected void Button1_Click(object sender, EventArgs e)
{
System.Threading.Thread s = new System.Threading.Thread(new System.Threading.ThreadStart(test)); //Create a new thread and set the method test() run in this thread
s.SetApartmentState(System.Threading.ApartmentState.STA); //Set the run mode 'STA'
s.Start(); //Start the thread
s.Join(); //Wait until thread run OK.
GridView1.DataSource = dt;
GridView1.DataBind();
msg.Text = "Get Data from 'ENQUEUE_READ' OK!";
}