这可能是因为在一个线程中的原因,可以在组件中重启一个线程。
public void BeginShowForm()
{
System.Threading.Thread thread1=new System.Threading.Thread(new ThreadStart(this.ShowForm));
thread1.ApartmentState=ApartmentState.STA;
thread1.Start();
thread1.Join();
}
public void ShowForm()
//private void PubLinkInterface_Load(object sender, System.EventArgs e)
{
try
{
/***********************Test********************************/
// this.dll = "PU_Control.dll";
// this.isClassName = "Genersoft.Drp.PU.Control.IM_EstQutity_Query";
// this.processID = "fqq";
// this.isCondition = "_CompanyID::1010::_Org::00000000000000000003::_WareHouse::00000000000000000066::_FiscalYear::2004::_FicalPeriod::12::_Module::IM";
/*************************End*******************************/
/***********************************************************
如果FocusUpdate存在则在注册表里寻找dll
否则为开发环境测试手动拷贝dll到相应的目录
***********************************************************/
RegistryKey hklm = Registry.LocalMachine ;
RegistryKey SOFTWARE = hklm.OpenSubKey ( "SOFTWARE" ) ;
RegistryKey Genersoft = SOFTWARE.OpenSubKey ( "Genersoft" ) ;
Genersoft=Genersoft.OpenSubKey ( "FocusUpdate" ) ;
this.error = "取注册表信息出错!";
if (Genersoft == null)
{
this.error = "开发环境构造DLL文件路径出错:";
AppDomain MyApp=AppDomain.CurrentDomain;
isAssemblyName = MyApp.BaseDirectory+this.dll;
//开发环境中:直接由AppDomain取dll文件 ;如果文件不存在,则根据dll文件名构造模块路径
//By Vaooya
FileInfo vfileInfo=new FileInfo(isAssemblyName);
if(!vfileInfo.Exists)
{
isAssemblyName=isAssemblyName.Substring(0,isAssemblyName.IndexOf(@"PUB_Debug\bin\Debug\"))+this.dll.Substring(0,this.dll.LastIndexOf("."))+@"\bin\"+this.dll;
}
}
else
{
isAssemblyName = Genersoft.GetValue("StorageLocation").ToString();
isAssemblyName = isAssemblyName +"\\"+ this.dll;
}
/********************************************
加载需要的dll动态链接库
********************************************/
this.error = "Assembly加载出错!";
System.Reflection.Assembly assem = Assembly.LoadFrom(this.isAssemblyName);
Type ClassType = assem.GetType(this.isClassName);
Object obj = ClassType.Assembly.CreateInstance(ClassType.FullName);
BindingFlags bf = BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.FlattenHierarchy| BindingFlags.SetField ;
PropertyInfo pi = ClassType.GetProperty("ProcessID");
pi.SetValue(obj,processID,null);
/********************************************
分割传递的isCondition参数
*********************************************/
this.error = "解析isCondition出错!";
Regex RegExp=new Regex("::");
string[] isConditions = RegExp.Split(isCondition);
Hashtable hl = new Hashtable();
for(int i=0;i<isConditions.Length;i++)
{
hl.Add(isConditions[i],isConditions[i+1]);
i++;
}
/*******************************************
构造出相应的键值对,SetValue给相应的类
******************************************/
this.error = "没有对应的属性!";
foreach(DictionaryEntry de in hl) //ht为一个Hashtable实例
{
string a = de.Key.ToString();//de.Key对应于key/value键值对key
string b = de.Value.ToString();//de.Key对应于key/value键值对value
if((a != "")&&(b != ""))
{
PropertyInfo pii = ClassType.GetProperty(a.ToString(),bf);
pii.SetValue(obj,b,null);
}
}
// Type[] bt = new Type[]{};
// MethodInfo mi = ClassType.GetMethod("ShowDialog",bt);
// mi.Invoke(obj,null);
Form form1=(Form)obj;
form1.MdiParent=this.ParentForm;
form1.ShowDialog();
form1.Focus();
if(this.Parent!=null)
this.Parent.Dispose();
else
this.Close();
}
catch(Exception ex)
{
MessageBox.Show(error+ex.Message);
}
}